I have the following class:
class StringContainer {
public:
StringContainer(const std::string& s1, const std::string& s2) {
string_array_ = {s1, s2};
}
std::vector<std::string> string_array_;
};
and then I create an object from this struct like this:
StringContainer con(s1, s2);
where s1 and s2 are non const std::string variables defined locally. I noticed that the assignment of string_array_ from the initializer list does not call std::string's constructor at least once. (not for the temporary object in initializer list or for the object inserted to the vector). I have read that this may be possible for trivially constructable classes, but one of the requirements of trivially constructorbility is to have implicit default constructor/copy constructor. However std::string (std::basic_string) has both defined. What am I missing here? If I want to write a string class that would make use of this optimization, what should I do?