Thanks a lot. I could make sense of your first one with some difficulty.
Gokulakannan Somasundaram escribió:With a little more effort:
On Fri, Jul 30, 2010 at 7:49 PM, <joaquin@tid.es <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?
#include <boost/mpl/begin_end.hpp>
#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
>
{};
#include <boost/mpl/contains.hpp>
#include <boost/mpl/distance.hpp>
#include <boost/mpl/find_if.hpp>
template<typename Index>
struct tag_list
{
typedef typename Index::tag_list type;
};
template<typename Tag,typename IndexList>
struct tag_pos:
boost::mpl::distance<
typename boost::mpl::begin<IndexList>::type,
typename boost::mpl::find_if<
IndexList,
boost::mpl::contains<tag_list<boost::mpl::_>,Tag>
>::type
>
{};
template<typename MultiIndexContainer,typename Tag>
struct is_ordered_index_with_tag:
is_ordered_index<
MultiIndexContainer,
tag_pos<Tag,typename MultiIndexContainer::index_type_list>::valueordered_unique<tag<struct i0>,identity<int> >,
>
{};
/* 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_non_unique<tag<struct i1>, identity<int> >,
hashed_unique<tag<struct i2>, identity<int> >,
hashed_non_unique<tag<struct i3>, identity<int> >,
sequenced<tag<struct i4> >BOOST_MPL_ASSERT ((is_ordered_index_with_tag<multi_t,i0>));
>
> 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>));
BOOST_MPL_ASSERT ((is_ordered_index_with_tag<multi_t,i1>));
BOOST_MPL_ASSERT_NOT((is_ordered_index_with_tag<multi_t,i2>));
BOOST_MPL_ASSERT_NOT((is_ordered_index_with_tag<multi_t,i3>));
BOOST_MPL_ASSERT_NOT((is_ordered_index_with_tag<multi_t,i4>));
int main(){}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users