boost::mpl::vector - getting to a type's base-offset

前端 未结 2 694
既然无缘
既然无缘 2021-01-13 22:41

Is it possible to get at the offset of a mpl::vector after performing a mpl::find on it ?

Put differently I want to do the

相关标签:
2条回答
  • 2021-01-13 23:21

    Their is a metafunction in the itterator category to do just this, it is called distance.

    p.s., apologies for answering my own question so quickly. I just stumbled on the solution.

    0 讨论(0)
  • 2021-01-13 23:32

    If what you're looking for is a kind of indexOf feature, I guess the example from Boost.MPL doc concerning find will do the trick:

    typedef vector<char,int,unsigned,long,unsigned long> types;
    typedef find<types,unsigned>::type iter;
    
    BOOST_MPL_ASSERT(( is_same< deref<iter>::type, unsigned > ));
    BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 );
    
    0 讨论(0)
提交回复
热议问题