I have the boost::variant
over set of non-default constructible (and maybe even non-moveable/non-copyable and non-copy/move constructible) classes with essentialy different non-default constructor prototypes, as shown below:
#include <boost/variant.hpp>
#include <string>
#include <list>
struct A { A(int) { ; } };
struct B { B(std::string) { ; } };
struct C { C(int, std::string) { ; } };
using V = boost::variant< A const, B const, C const >;
using L = std::list< V >;
int main()
{
L l;
l.push_back(A(1)); // an extra copy/move operation
l.push_back(B("2")); // an extra copy/move operation
l.push_back(C(3, "3")); // an extra copy/move operation
l.emplace_back(4);
l.emplace_back(std::string("5"));
// l.emplace_back(3, std::string("3")); // error here
return 0;
}
I expect, that std::list::emplace_back
allows me to construct-and-insert (in single operation) new objects (of all the A
, B
, C
types) into list, even if they have T & operator = (T const &) = delete;
/T & operator = (T &&) = delete;
and T(T const &) = delete;
/T(T &&) = delete;
. But what should I do, if constructor is a non-conversion one? I.e. have more, than one parameter. Or what I should to do if two different variant's underlying types have ambiguous constructor prototypes? In my opinion, this is the defect of implementation of the boost::variant
library in the light of the new features of C++11 standard, if any at all can be applyed to solve the problem.
I specifically asked about std::list
and boost::variant
in superposition, because they are both internally implement the pimpl idiom in some form, as far as I know (say, boost::variant
currently designed by means of temporary heap backup approach).