Skip to content

Instantly share code, notes, and snippets.

@zaltoprofen
Created November 7, 2014 02:56
Show Gist options
  • Save zaltoprofen/1c14630653d4cdbfbd54 to your computer and use it in GitHub Desktop.
Save zaltoprofen/1c14630653d4cdbfbd54 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <string>
template<typename T, typename Container = std::vector<T>>
class ChainContainer : public Container {
struct chain{
chain(ChainContainer& c): container(c){}
chain& operator()(T val){
container.push_back(val);
return *this;
}
private:
ChainContainer &container;
};
public:
chain start(){
return chain(*this);
}
};
int main(int argc, char const* argv[])
{
ChainContainer<std::string> cont;
cont.start()("hoge")("fuga")("foo")("bar");
for (auto&& var : cont) {
std::cout << var << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment