
Joaquin M Lopez Munoz <joaquin <at> tid.es> writes:
Joaquin M Lopez Munoz <joaquin <at> tid.es> writes:
Elizabeta <elizabeta.petreska <at> gmail.com> writes:
Hi how to test if the first index of boost::multi-index is key based or sequence based at compile time[...]
This can do:
Correction: this is terser and is prepared for Boost 1.59 (which includes a new type of key-based indices, namely ranked indices):
Just for the fun of it, the following variation is more future-proof in the sense that it does not depend on the particular catalog of indices that Boost.MultiIndex is providing for a given Boost version: #include <boost/multi_index_container_fwd.hpp> #include <boost/mpl/bool.hpp> #include <boost/mpl/front.hpp> template<typename Value,typename Index> using mono_index_container= boost::multi_index_container< Value, boost::multi_index::indexed_by<Index> >; template<typename T> struct void_t { typedef void type; }; template<typename MultiIndexContainer,typename=void> struct is_first_index_key_based:boost::mpl::false_{}; template<typename MultiIndexContainer> struct is_first_index_key_based< MultiIndexContainer, typename void_t< typename mono_index_container< typename MultiIndexContainer::value_type, typename boost::mpl::front< typename MultiIndexContainer::index_specifier_type_list >::type >::key_type >::type >:boost::mpl::true_{}; This uses Walter Brown's void_t technique to determine whether a multi_index_container, constructed out of the first index of a different, user-provided multi_index_container, has an embedded key_type. The mono_index_container intermediate step is needed because otherwise key_type might exist but be inaccesible (for instance if the first index is sequenced and the second ordered). All in all, you're better off with the previous code, as this is likely to take longer to compile. Full example at http://coliru.stacked-crooked.com/a/42912fc5803143e2 Joaquín M López Muñoz Telefónica