// author: Filip Roséen // source: http://b.atch.se/posts/constexpr-meta-container #ifndef ATCH_META_LIST_HPP #define ATCH_META_LIST_HPP #include #include "type_list.hpp" #include "meta_counter.hpp" namespace atch { namespace { template struct meta_list { using counter = atch::meta_counter>; using size_type = typename counter::size_type; template struct ident { friend auto adl_lookup (ident); static constexpr size_type value = N; }; template struct ident<0, Dummy> { friend auto adl_lookup (ident<0>) { return atch::type_list<> {}; } }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template struct writer { friend auto adl_lookup (ident) { return Value {}; } static constexpr size_type value = Ident::value; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template< class State, class H = meta_list, class Ident = typename H::template ident > static constexpr size_type push_state (size_type R = writer::value) { return R; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template< class H = meta_list, size_type N = H::counter::value ()> using value_ident = typename H::template ident; template< class H = meta_list, class Ident = typename H::template value_ident<> > using value = decltype (adl_lookup (Ident {})); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template static constexpr void push ( size_type = push_state< typename H::template value<>::template push::result > () ) {} template static constexpr void pop ( size_type = push_state< typename H::template value<>::init::result > () ) {} template static constexpr void set ( size_type = push_state< typename H::template value<>::template set::result > () ) {} }; }} #endif /* include guard */