Last active
August 29, 2015 14:01
-
-
Save miselin/165f35068fb18fee639d to your computer and use it in GitHub Desktop.
This file contains 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 <list> | |
template <typename T> | |
class _basic_tuple { | |
public: | |
_basic_tuple() : _list() {} | |
virtual ~_basic_tuple() {} | |
_basic_tuple &operator , (T other) { | |
_list.push_back(other); | |
return const_cast<_basic_tuple&>(*this); | |
} | |
operator int () { | |
return _list.size(); | |
} | |
void dump() { | |
std::cout << "( "; | |
for(auto it : _list) { | |
std::cout << it << " "; | |
} | |
std::cout << ")" << std::endl; | |
} | |
private: | |
std::list<T> _list; | |
}; | |
class _tuple { | |
public: | |
template<typename T> | |
_basic_tuple<T> operator , (T val) { | |
return _basic_tuple<T>(), val; | |
} | |
} Tuple; | |
int main(int argc, char * argv[]) { | |
(Tuple, 1, 2).dump(); | |
(Tuple, "hello", "world").dump(); | |
int count = (Tuple, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | |
std::cout << count << std::endl; | |
return 0; | |
} |
This file contains 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
( 1 2 ) | |
( hello world ) | |
10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment