Last active
May 29, 2016 05:21
-
-
Save milesrout/99a28cfa0ecdea6a8f8e 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 <type_traits> | |
using namespace std; | |
#define ALVIN_SASSERT_IS_SAME(actual, expected) static_assert(std::is_same<actual, expected>::value, "Expected " #expected ", got " #actual "."); | |
struct Type {}; | |
struct Function { | |
template <typename T> | |
struct from { | |
template <typename U> | |
struct to { | |
using type = Type; | |
}; | |
using type = to<Type>; | |
}; | |
using type = from<Type>::to<from<Type>::to<Type>>; | |
}; | |
struct List { | |
using type = Function::from<Type>::to<Type>; | |
template <typename T> | |
struct of { | |
using type = Type; | |
}; | |
}; | |
struct Int { | |
using type = Type; | |
}; | |
template <int i> | |
struct IntegerLiteral { | |
using type = Int; | |
}; | |
// repeat x = [x] ++ (repeat x) | |
struct repeat { | |
template <typename T> | |
using type = typename Function::from<List::of<T>>::template to<List::of<T>>; | |
template <typename x> | |
struct value { | |
using type = List::of<typename x::type>; | |
}; | |
}; | |
ALVIN_SASSERT_IS_SAME( | |
repeat::value<IntegerLiteral<1>>::type, | |
List::of<Int> | |
); | |
ALVIN_SASSERT_IS_SAME( | |
repeat::value<IntegerLiteral<1>>::type, | |
List::of<Int> | |
); | |
ALVIN_SASSERT_IS_SAME( | |
Function::from<Int>::type, | |
Function::from<Type>::to<Type>); | |
int main(){} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment