This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Intializing C++ Containers


In C++ we can initialize a char* vector (array) like so:

  char* vec[] = { "s1", "s2" };

Is there any equivalent way to do it for a C++ vector?  I don't think
so--except by constructing a std::vector<std::string> from the char* array
at runtime.

So the question is: wouldn't that be a "good thing" for a C++ extension to
g++?  It would continue the move away from the "dangerous" C string and it
would conserve space since we wouldn't need two copies of the array (or does
g++ do some behind-the-scenes optimizations?).  My idea of such an
initialization is:

  std::vector<std::string> vec = { "s1, "s2 };

Thanks.

Tom Browder




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]