Using boost::assign::list_of

无人久伴 提交于 2019-11-29 06:10:38
Sven

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.

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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!