Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 957039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:38:10+00:00 2026-05-16T00:38:10+00:00

In boost multi-index, can I verify whether a particular index type is ordered/not through

  • 0

In boost multi-index, can I verify whether a particular index type is ordered/not through meta programming?
There are the ordered indexes, hash indexes, sequence indexes etc. Can I find them out through meta programming?

Suppose there is a index like:

 int main()
 {
    typedef multi_index_container<double> double_set;
    return 0;
 }

I want to know whether the double_set index is ordered or hashed or sequenced. Of course in this case, it is ordered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:38:11+00:00Added an answer on May 16, 2026 at 12:38 am

    Yes:

    #include <boost/multi_index_container.hpp>
    #include <boost/multi_index/ordered_index.hpp>
    #include <boost/multi_index/hashed_index.hpp>
    #include <boost/multi_index/sequenced_index.hpp>
    #include <boost/multi_index/random_access_index.hpp>
    
    #include <boost/mpl/bool.hpp>
    #include <boost/mpl/or.hpp>
    #include <boost/mpl/at.hpp>
    #include <boost/mpl/not.hpp>
    #include <boost/mpl/distance.hpp>
    #include <boost/mpl/begin.hpp>
    
    namespace mpl = boost::mpl;
    namespace mi  = boost::multi_index;
    
    //
    // checking for ordered_unique:
    //
    template <typename MI>
    struct is_nth_index_ordered_unique_helper : mpl::false_ {};
    
    template <typename KeyFromValue, typename Compare>
    struct is_nth_index_ordered_unique_helper<
        mi::ordered_unique<KeyFromValue,Compare>
    > : mpl::true_ {};
    
    template <typename TagList, typename KeyFromValue, typename Compare>
    struct is_nth_index_ordered_unique_helper<
        mi::ordered_unique<TagList,KeyFromValue,Compare>
    > : mpl::true_ {};
    
    template <typename MI, int N>
    struct is_nth_index_ordered_unique
        : is_nth_index_ordered_unique_helper<
             typename mpl::at_c< typename MI::index_specifier_type_list, N >::type
          > {};
    
    //
    // checking for ordered_non_unique:
    //
    
    template <typename MI>
    struct is_nth_index_ordered_non_unique_helper : mpl::false_ {};
    
    template <typename KeyFromValue, typename Compare>
    struct is_nth_index_ordered_non_unique_helper<
        mi::ordered_non_unique<KeyFromValue,Compare>
    > : mpl::true_ {};
    
    template <typename TagList, typename KeyFromValue, typename Compare>
    struct is_nth_index_ordered_non_unique_helper<
        mi::ordered_non_unique<TagList,KeyFromValue,Compare>
    > : mpl::true_ {};
    
    template <typename MI, int N>
    struct is_nth_index_ordered_non_unique
        : is_nth_index_ordered_non_unique_helper<
             typename mpl::at_c< typename MI::index_specifier_type_list, N >::type
          > {};
    
    //
    // Combined (ordered_{non_,}unique):
    //
    
    template <typename MI, int N>
    struct is_nth_index_ordered
        : mpl::or_<
             is_nth_index_ordered_unique<MI,N>,
             is_nth_index_ordered_non_unique<MI,N>
          > {};
    
    //
    // checking for sequenced:
    //
    
    template <typename MI>
    struct is_nth_index_sequenced_helper : mpl::false_ {};
    
    template <typename TagList>
    struct is_nth_index_sequenced_helper<
        mi::sequenced<TagList>
    > : mpl::true_ {};
    
    template <typename MI, int N>
    struct is_nth_index_sequenced
        : is_nth_index_sequenced_helper<
             typename mpl::at_c< typename MI::index_specifier_type_list, N >::type
          > {};
    
    //
    // test with example container:
    //
    typedef mi::multi_index_container<double> double_set_1;
    
    BOOST_MPL_ASSERT(( is_nth_index_ordered<double_set_1,0> ));
    BOOST_MPL_ASSERT(( mpl::not_< is_nth_index_sequenced<double_set_1,0> > ));
    // or
    BOOST_STATIC_ASSERT(( is_nth_index_ordered<double_set_1,0>::value ));
    BOOST_STATIC_ASSERT(( mpl::not_< is_nth_index_sequenced<double_set_1,0> >::value ));
    
    //
    // And now with tag dispatch:
    //
    
    template <typename MI, typename Tag>
    struct tag_to_n
        : mpl::distance<
              typename mpl::begin<typename MI::index_type_list>::type,
              typename MI::template index<Tag>::iter
          > {};
    
    template <typename MI, typename Tag>
    struct is_tagged_index_ordered_unique
        : is_nth_index_ordered_unique<MI,tag_to_n<MI,Tag>::value> {};
    
    template <typename MI, typename Tag>
    struct is_tagged_index_ordered_non_unique
        : is_nth_index_ordered_non_unique<MI,tag_to_n<MI,Tag>::value> {};
    
    template <typename MI, typename Tag>
    struct is_tagged_index_ordered
        : is_nth_index_ordered<MI,tag_to_n<MI,Tag>::value> {};
    
    template <typename MI, typename Tag>
    struct is_tagged_index_sequenced
        : is_nth_index_sequenced<MI,tag_to_n<MI,Tag>::value> {};
    
    
    //
    // test with another example container:
    //
    
    struct as_set {};
    struct as_list {};
    
    typedef mi::multi_index_container<
        double,
        mi::indexed_by<
            mi::sequenced< mi::tag<as_list> >,
            mi::ordered_non_unique< mi::tag<as_set>, mi::identity<double> >
        >
    > double_set_2;
    
    void fun() {
        double_set_2 ds2;
    }
    
    BOOST_MPL_ASSERT(( is_nth_index_sequenced<double_set_2,0> ));
    BOOST_MPL_ASSERT(( is_nth_index_ordered<double_set_2,1> ));
    BOOST_MPL_ASSERT(( mpl::not_< is_nth_index_ordered<double_set_2,0> > ));
    BOOST_MPL_ASSERT(( mpl::not_< is_nth_index_sequenced<double_set_2,1> > ));
    
    BOOST_MPL_ASSERT(( is_tagged_index_sequenced<double_set_2,as_list> ));
    BOOST_MPL_ASSERT(( is_tagged_index_ordered<double_set_2,as_set> ));
    BOOST_MPL_ASSERT(( mpl::not_< is_tagged_index_ordered<double_set_2,as_list> > ));
    BOOST_MPL_ASSERT(( mpl::not_< is_tagged_index_sequenced<double_set_2,as_set> > ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do one multi map(4 variables) using boost- multi index. Can
I have a very simplified question regarding sequenced indices in boost multi index. The
I'm currently using Boost's multi-index to help keep track of how many times a
I'm trying to use Boost's multi-index container for fast look up, but I'm having
In C++ and other languages, add-on libraries implement a multi-index container, e.g. Boost.Multiindex .
I have a boost multi index container thus. using namespace boost::multi_index; template < typename
I am using boost::multi_index with a data type I'd like to index based on
I'm programming an agent-based simulation and have decided that Boost's MultiIndex is probably the
Say I've got an N-dimensional boost::multi_array (of type int for simplicity), where N is
I'm trying to figure out if the boost::multi_array constructor or resize method can throw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.