Created
January 9, 2013 13:52
-
-
Save robertmaynard/4493256 to your computer and use it in GitHub Desktop.
example to create a struct that holds indicies as template arguments.
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
//holds a sequence of integers. | |
template<int ...> | |
struct static_indices { }; | |
//generate a struct with template args of incrementing values from Start to End | |
//which is inclusive at the start, exclusive at end. | |
//start must be less than end | |
template<int Start, int End, int ...S> | |
struct make_indices { typedef typename make_indices<Start,End-1, End-1, S...>::type type; }; | |
//generate a struct with tempalte args of incrementing values from Start to End | |
//which is inclusive at the start, exclusive at end. | |
//start must be less than end | |
template<int Start, int ...S> | |
struct make_indices<Start,Start, S...> { typedef static_indices<S...> type; }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment