Skip to content

Instantly share code, notes, and snippets.

@robertmaynard
Created January 9, 2013 13:52
Show Gist options
  • Save robertmaynard/4493256 to your computer and use it in GitHub Desktop.
Save robertmaynard/4493256 to your computer and use it in GitHub Desktop.
example to create a struct that holds indicies as template arguments.
//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