Last active
October 13, 2015 06:48
-
-
Save socantre/4156015 to your computer and use it in GitHub Desktop.
Left-to-right type syntax in C++ with type aliases
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
template<typename T> using ptr = T*; | |
template<typename T> using ref = T&; | |
template<typename T> using rref = T&&; | |
template<typename T> using constant = T const; | |
template<typename T> using volat = T volatile; | |
template<typename T, class C> using mem_ptr = T C::*; | |
template<std::intmax_t N, typename T> using raw_array = T[N]; | |
template<typename RetT, typename... Args> using func = RetT(Args...); | |
extern "C" template<typename T> using c_linkage = T; | |
extern "C++" template<typename T> using cpp_linkage = T; | |
// gives us left-to-right type syntax | |
// consistent with template type syntax | |
ptr<int> a, b; // solves the int* a, b; problem | |
// can be mixed easily with the normal type declaration syntax | |
ptr<int> foo(); // vs func<ptr<int>> foo; | |
// does not mix with 'auto' | |
ptr<auto> x = new int; // error | |
// instead we can simply use 'auto' alone | |
auto x = new int; | |
// until we start using 'auto' for implicit templates, that is: | |
void foo(auto &x); // void foo(ref<auto> x); won't work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment