Created
March 18, 2014 09:26
-
-
Save benloong/9616546 to your computer and use it in GitHub Desktop.
c++11 meta sequence
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
template<typename T, T... _Rest> | |
struct array_pack; | |
template<typename T> | |
struct array_pack<T>{}; | |
template<typename T, T _This, T... _Rest> | |
struct array_pack<T, _This, _Rest...> : private array_pack<T, _Rest...> | |
{ | |
const T & operator[](const int pos) | |
{ | |
//as cpp memory layout, indexing reversely | |
return ((T *)this)[sizeof...(_Rest)-pos]; | |
} | |
constexpr int size() const | |
{ | |
return sizeof...(_Rest)+1; | |
} | |
private: | |
T _this = _This; | |
}; |
Author
benloong
commented
Mar 18, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment