adding elements to a std::container in a single expression
until now I've usually written my own template to do this: template<typename T> struct push_back_container:T { push_back_container &_push_back(const typename T::value_type &_r) { push_back(_r); return *this; } }; one can use this like this: push_back_container<std::vector<something>
()._push_back(something1)._push_back(_something2)
Is there some more elegant way to do this? Peter
On Sun, Aug 14, 2011 at 3:26 AM, Peter Foelsche <foelsche@sbcglobal.net> wrote:
push_back_container<std::vector<something>
()._push_back(something1)._push_back(_something2)
Is there some more elegant way to do this?
You might want to have a boost.assign. #include <boost/assign/list_of.hpp> using namespace boost::assign; std::vector<int> = list_of(1)(2)(3)(4); Or #include <boost/assign/std/vector.hpp> using namespace boost::assign; vector<int> values; values += 1,2,3,4; Best regards, Christoph
participants (2)
-
Christoph Heindl
-
Peter Foelsche