Topic: std::basic_string<> copy
Author: jlolieux@btinternet.com ("Jacques Lolieux")
Date: Tue, 10 Sep 2002 21:52:09 +0000 (UTC) Raw View
Is there any reason why the standard does not provide copy operations for
std::basic_string<> differing only by their allocator types?
For example, I have something like this in my code:
std::string s = "abcd";
std::basic_string<char, std::char_traits<char>, my_allocator>
t(s.begin(), s.end());
t.assign(s.begin(), s.end());
t = s.c_str();
Note that s's type and t's type only differ in their allocators. It is
trivial to provide copy constructors and copy assignment operators so that
the following code would be legal:
//
// Not standard conforming code, AFAIK
//
std::string s = "abcd";
std::basic_string<char, std::char_traits<char>, my_allocator> t(s);
t = s;
Is their something I am missing or is it that nobody thought it was worth
the effort to define such copy functions in the standard library? If it is
an oversight is there any plan to define those copy functions in the next
standard?
The same question can be asked for std::vector<> and other standard
containers as well.
Jacques
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]