Created
November 7, 2014 02:56
-
-
Save zaltoprofen/1c14630653d4cdbfbd54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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