<
ken...@googlemail.com> wrote:
> Hello, if I have a different allocator, can I use that allocator to
> allocate memory with vector or string as private member? How so?
>
> actual code:
>
> #ifndef COMMAND_LINE_H
> #define COMMAND_LINE_H
>
> namespace bos {
>
> //template<typename Allocator = std::allocator<T>>
What is T?
It's not possible to use the same concrete allocator for two different
types.
If you are sure, that you only use trait-style allocators (i.e. all your
custom allocators are templates), you can make the 'Allocator' template
parameter itself a template:
template <template<class> class Allocator = std::allocator>
Or since you already know the member types you are using you could specify
them directly:
template <class AllocChar = std::allocator<char>, class AllocString =
std::allocator<std::basic_string<char, std::char_traits<char>, AllocChar> >
>
> class basic_command_line {
> public:
> basic_command_line(int argc, char * argv[]);
> basic_command_line(const command_line& other) = delete;
> basic_command_line & operator=(const command_line& other) = delete;
> basic_command_line(const command_line&& other) = delete;
> basic_command_line & operator=(const command_line&& other) = delete;
> void print() const;
> ~basic_command_line();
> private:
> std::vector<std::string> args_;
> //std::vector<std::string<Allocater<char>,
> Allocator<std::string>> args_;
With the first template suggestion, this would be:
std::vector<std::basic_string<char, std::char_traits<char>, Allocator<char>
>, Allocator<std::basic_string<char, std::char_traits<char>, Allocator<char> > > > args_;
And with the second one:
std::vector<std::basic_string<char, std::char_traits<char>, AllocChar>,
AllocString> args_;
> };
>
> typedef basic_command_line command_line;
>
> }
>
> #endif
(Untested, I hope I got all those pointy brackets right)
Unfortunately, this is all rather clumsy.
Tobi