c++ - Add multiple values to a vector -



c++ - Add multiple values to a vector -

i have vector of ints want add together multiple values too many values add together using lot of push_backs. there method of adding multiple values @ end of vector. along lines of this:

std::vector<int> values values += {3, 9, 2, 5, 8, etc};

i found boost has this, not having include boost.

#include <boost/assign/std/vector.hpp> using namespace boost::assign; { std::vector<int> myelements; myelements += 1,2,3,4,5; }

which seems declared this:

template <class v, class a, class v2> inline list_inserter<assign_detail::call_push_back<std::vector<v,a> >, v> operator+=( std::vector<v, a>& c, v2 v ) { homecoming push_back( c )( v ); }

is there c++/c++11 way or, if not, how implemented?

you can create operator:

class="lang-c++ prettyprint-override">template <class t> std::vector<t>& operator+=(std::vector<t>& lhs, std::initializer_list<t> l) { lhs.insert(std::end(lhs), l); homecoming lhs; }

c++ vector addition

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -