This compiles:
std::vector value = boost::assign::list_of(1)(2);
But not this:
Constructor(std::vector
I'm using this template to make temporary instance of std::vector in-place:
#include <vector>
namespace Util {
//init vector
template <typename ELEMENT_TYPE > struct vector_of
: public std::vector<ELEMENT_TYPE>
{
vector_of(const ELEMENT_TYPE& t)
{
(*this)(t);
}
vector_of& operator()(const ELEMENT_TYPE& t)
{
this->push_back(t);
return *this;
}
};
}//namespace Util
Usage would look like this:
Constructor (Util::vector_of<int>(1)(2));
Constructor signature would look like this:
Constructor(const std::vector<int>& value)
{
_value = value;
}
This is a annoying problem, we also had some time before. We fixed it by using the convert_to_container
method:
Constructor c(boost::assign::list_of(1)(2).convert_to_container<std::vector<int> >() );
There are more issues with std::list using in constructor too. See Pass std::list to constructor using boost's list_of doesn't compile for the appropriate answer.