// author: Filip Roséen // source: http://b.atch.se/posts/constexpr-meta-container #ifndef ATCH_META_COUNTER_HPP #define ATCH_META_COUNTER_HPP #include namespace atch { namespace { template struct meta_counter { using size_type = std::size_t; template struct ident { friend constexpr size_type adl_lookup (ident); static constexpr size_type value = N; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template struct writer { friend constexpr size_type adl_lookup (Ident) { return Ident::value; } static constexpr size_type value = Ident::value; }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template {})> static constexpr size_type value_reader (int, ident) { return N; } template static constexpr size_type value_reader (float, ident, size_type R = value_reader (0, ident ())) { return R; } static constexpr size_type value_reader (float, ident<0>) { return 0; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template static constexpr size_type value (size_type R = value_reader (0, ident {})) { return R; } template static constexpr size_type next (size_type R = writer>::value) { return R; } }; }} #endif /* include guard */