Created
February 20, 2014 13:36
-
-
Save uchan-nos/9113701 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 <utility> | |
#include <string> | |
using namespace std; | |
// {{{ | |
struct ListTerminator | |
{ | |
}; | |
const ListTerminator NIL {}; | |
template <typename T, typename ...Remains> | |
struct List | |
{ | |
typedef typename std::pair<T, typename List<Remains...>::type> type; | |
}; | |
template <typename T> | |
struct List<T> | |
{ | |
typedef std::pair<T, ListTerminator> type; | |
}; | |
// }}} | |
int add(int a, int b) | |
{ | |
return a + b; | |
} | |
int main(void) | |
{ | |
List<int, string, int (*)(int, int)>::type v { 41, { "hoge", { add, NIL } } }; | |
cout << v.first << endl; | |
cout << v.second.first << endl; | |
cout << v.second.second.first(3, 5) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment