Created
March 5, 2015 04:49
-
-
Save nyuichi/d63b371341d38f2795fc 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> | |
| #include <typeinfo> | |
| #include <typeindex> | |
| template<typename T> struct Key; | |
| template<> struct Key<int> { static constexpr std::size_t value = 0; }; | |
| template<> struct Key<float> { static constexpr std::size_t value = 1; }; | |
| template<typename T, typename U> | |
| struct Sort | |
| { | |
| using T1 = typename std::conditional<Key<T>::value <= Key<U>::value, T, U>::type; | |
| using T2 = typename std::conditional<Key<T>::value <= Key<U>::value, U, T>::type; | |
| }; | |
| template<typename T, typename U> | |
| struct A | |
| { | |
| T t; | |
| U u; | |
| }; | |
| template<typename T, typename U> | |
| struct A_proxy | |
| { | |
| A<typename Sort<T, U>::T1, typename Sort<T, U>::T2> s; | |
| }; | |
| int main() | |
| { | |
| A_proxy<int, float> a; | |
| a.s.t = 10; | |
| a.s.u = 0.1; | |
| std::cout << a.s.t << ' ' << a.s.u << std::endl; | |
| A_proxy<float, int> b; | |
| b.s.t = 10; | |
| b.s.u = 0.1; | |
| std::cout << b.s.t << ' ' << b.s.u << std::endl; | |
| a.s = b.s; // same! | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment