Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <utility>
- #include <iostream>
- struct Obj
- {
- size_t v;
- };
- template <size_t I>
- static Obj foo() { return Obj{I}; }
- template <class T, size_t... I>
- static T switch_(size_t i, std::index_sequence<I...>)
- {
- T ret;
- const bool ar[] = {
- ((i == I) ? (ret = foo<I>(),false):false, false)... };
- return ret;
- }
- template <class T, size_t Max>
- static T do_switch(size_t i)
- {
- return switch_<T>(i, std::make_index_sequence<Max>());
- }
- int main(int argc, char** argv)
- {
- auto ret = do_switch<Obj, 10>(argc);
- std::cout << ret.v << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement