Skip to content

Instantly share code, notes, and snippets.

@uchan-nos
Created February 20, 2014 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uchan-nos/9113701 to your computer and use it in GitHub Desktop.
Save uchan-nos/9113701 to your computer and use it in GitHub Desktop.
#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