Boost logo

Boost Users :

Subject: Re: [Boost-users] A doubt in Boost multi index
From: joaquin_at_[hidden]
Date: 2010-07-30 07:49:02


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:

  #include <boost/multi_index/ordered_index.hpp>
  #include <boost/mpl/at.hpp>
  #include <boost/mpl/bool.hpp>

  template<typename IndexSpecifier>
  struct is_ordered_index_impl:boost::mpl::false_{};

  template<typename KeyFromValue,typename Compare>
  struct is_ordered_index_impl<
    boost::multi_index::ordered_unique<KeyFromValue,Compare>
>:boost::mpl::true_{};

  template<typename KeyFromValue,typename Compare>
  struct is_ordered_index_impl<
    boost::multi_index::ordered_non_unique<KeyFromValue,Compare>
>:boost::mpl::true_{};

  template<typename MultiIndexContainer,int N>
  struct is_ordered_index:
    is_ordered_index_impl<
      typename boost::mpl::at_c<
        typename MultiIndexContainer::index_specifier_type_list,
        N
>::type
>
  {};

  /* testing */

  #include <boost/multi_index_container.hpp>
  #include <boost/multi_index/sequenced_index.hpp>
  #include <boost/multi_index/hashed_index.hpp>
  #include <boost/multi_index/identity.hpp>
  #include <boost/mpl/assert.hpp>

  using namespace boost::multi_index;

  typedef multi_index_container<
    int,
    indexed_by<
      ordered_unique<identity<int> >,
      ordered_non_unique<identity<int> >,
      hashed_unique<identity<int> >,
      hashed_non_unique<identity<int> >,
      sequenced<>
>
> multi_t;

  BOOST_MPL_ASSERT ((is_ordered_index<multi_t,0>));
  BOOST_MPL_ASSERT ((is_ordered_index<multi_t,1>));
  BOOST_MPL_ASSERT_NOT((is_ordered_index<multi_t,2>));
  BOOST_MPL_ASSERT_NOT((is_ordered_index<multi_t,3>));
  BOOST_MPL_ASSERT_NOT((is_ordered_index<multi_t,4>));

  int main(){}

HTH,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net