Boost logo

Boost Users :

Subject: [Boost-users] adding elements to a std::container in a single expression
From: Peter Foelsche (foelsche_at_[hidden])
Date: 2011-08-13 21:26:01


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net