Gokulakannan Somasundaram escribió:
On Fri, Jul 30, 2010 at 7:49 PM, mailto:joaquin@tid.es> wrote:
Gokulakannan Somasundaram escribió:
Hi,
In boost multi-index, can i verify whether a particular
index type is
ordered/not or not through meta programming? There are the
ordered
indexes, hash indexes, sequence indexes etc. Can i find them out
through meta programming?
You can if you're given the multi_index_containr type and the position
of the index:
Thanks a lot. Is it possible to do the same with named tags?
With a little more effort:
#include
#include
#include
template<typename IndexSpecifier>
struct is_ordered_index_impl:boost::mpl::false_{};
template
struct is_ordered_index_impl<
boost::multi_index::ordered_unique
:boost::mpl::true_{};
template
struct is_ordered_index_impl<
boost::multi_index::ordered_non_unique
:boost::mpl::true_{};
template
struct is_ordered_index:
is_ordered_index_impl<
typename boost::mpl::at_c<
typename MultiIndexContainer::index_specifier_type_list,
N
>::type
>
{};
#include
#include
#include
#include
template<typename Index>
struct tag_list
{
typedef typename Index::tag_list type;
};
template
struct tag_pos:
boost::mpl::distance<
typename boost::mpl::begin<IndexList>::type,
typename boost::mpl::find_if<
IndexList,
boost::mpl::containsboost::mpl::_,Tag>
>::type
>
{};
template
struct is_ordered_index_with_tag:
is_ordered_index<
MultiIndexContainer,
tag_pos::value
>
{};
/* testing */
#include
#include
#include
#include
#include
using namespace boost::multi_index;
typedef multi_index_container<
int,
indexed_by<
ordered_unique,
ordered_non_unique,
hashed_unique,
hashed_non_unique,
sequenced
>
multi_t;
BOOST_MPL_ASSERT ((is_ordered_index));
BOOST_MPL_ASSERT ((is_ordered_index));
BOOST_MPL_ASSERT_NOT((is_ordered_index));
BOOST_MPL_ASSERT_NOT((is_ordered_index));
BOOST_MPL_ASSERT_NOT((is_ordered_index));
BOOST_MPL_ASSERT ((is_ordered_index_with_tag));
BOOST_MPL_ASSERT ((is_ordered_index_with_tag));
BOOST_MPL_ASSERT_NOT((is_ordered_index_with_tag));
BOOST_MPL_ASSERT_NOT((is_ordered_index_with_tag));
BOOST_MPL_ASSERT_NOT((is_ordered_index_with_tag));
int main(){}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo