I want to store a sequence of string in a queue. This seems pretty simple if i use the member function push()
queue test;
string s0(\"s0\"), s1(
I would not really do it, but if you really feel that you need to provide that syntax, you can write an inserter adapter...
template
class inserter_type {
public:
typedef C container_type;
typedef typename container_type::value_type value_type;
explicit inserter_type( container_type & container ) : container(container) {}
inserter_type& operator<<( value_type const & value ) {
container.push( value );
return *this;
}
private:
container_type & container;
};
template
inserter_type inserter( C & container ) {
return inserter_type(container);
}
int main() {
std::queue q;
inserter(q) << "Hi" << "there";
}