mirror of
https://github.com/boostorg/mpl.git
synced 2025-08-02 22:34:31 +02:00
1) 'Not found' result is void_; 2) Uses refactored find_if_pred.
[SVN r20714]
This commit is contained in:
@@ -18,18 +18,16 @@
|
||||
#define BOOST_MPL_INDEX_IF_HPP_INCLUDED
|
||||
|
||||
#include "boost/mpl/aux_/config/workaround.hpp"
|
||||
#include "boost/mpl/aux_/find_if_pred.hpp"
|
||||
#include "boost/mpl/aux_/iter_fold_if_impl.hpp"
|
||||
#include "boost/mpl/aux_/iter_apply.hpp"
|
||||
#include "boost/mpl/always.hpp"
|
||||
#include "boost/mpl/apply.hpp"
|
||||
#include "boost/mpl/begin_end.hpp"
|
||||
#include "boost/mpl/bool.hpp"
|
||||
#include "boost/mpl/if.hpp"
|
||||
#include "boost/mpl/int.hpp"
|
||||
#include "boost/mpl/lambda.hpp"
|
||||
#include "boost/mpl/next.hpp"
|
||||
#include "boost/mpl/not.hpp"
|
||||
#include "boost/mpl/or.hpp"
|
||||
#include "boost/mpl/void.hpp"
|
||||
#include "boost/mpl/aux_/void_spec.hpp"
|
||||
#include "boost/mpl/aux_/lambda_support.hpp"
|
||||
#include "boost/type_traits/is_same.hpp"
|
||||
@@ -39,21 +37,6 @@ namespace mpl {
|
||||
|
||||
namespace aux {
|
||||
|
||||
// slight modification of Aleksey Gurtovoy's find_if_pred
|
||||
// (could replace find_if_pred)
|
||||
template< typename Predicate, typename LastIterator >
|
||||
struct index_if_pred
|
||||
{
|
||||
template< typename State, typename Iterator >
|
||||
struct apply
|
||||
{
|
||||
typedef not_< or_<
|
||||
is_same<Iterator,LastIterator>
|
||||
, aux::iter_apply1<Predicate,Iterator>
|
||||
> > type;
|
||||
};
|
||||
};
|
||||
|
||||
struct index_if_op
|
||||
{
|
||||
template < typename Index, typename Iterator >
|
||||
@@ -88,7 +71,7 @@ struct index_if
|
||||
first_
|
||||
, int_<0>
|
||||
, aux::index_if_op
|
||||
, aux::index_if_pred<pred_,last_>
|
||||
, aux::find_if_pred<pred_,last_>
|
||||
, void
|
||||
, always<false_>
|
||||
>
|
||||
@@ -104,7 +87,7 @@ struct index_if
|
||||
public:
|
||||
typedef typename if_<
|
||||
is_same< result_iterator_,last_ >
|
||||
, int_<-1>
|
||||
, void_
|
||||
, result_index_
|
||||
>::type type;
|
||||
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "boost/static_assert.hpp"
|
||||
#include "boost/mpl/list.hpp"
|
||||
#include "boost/mpl/void.hpp"
|
||||
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
@@ -30,10 +31,11 @@ int test_main(int , char* [])
|
||||
typedef mpl::index_of< types, float >::type index_of_float;
|
||||
typedef mpl::index_of< types, char >::type index_of_char;
|
||||
|
||||
BOOST_STATIC_ASSERT( index_of_int::value == 0 );
|
||||
BOOST_STATIC_ASSERT( index_of_double::value == 1 );
|
||||
BOOST_STATIC_ASSERT( index_of_float::value == 2 );
|
||||
BOOST_STATIC_ASSERT( index_of_char::value == -1 ); // 'not found'
|
||||
BOOST_STATIC_ASSERT(( index_of_int::value == 0 ));
|
||||
BOOST_STATIC_ASSERT(( index_of_double::value == 1 ));
|
||||
BOOST_STATIC_ASSERT(( index_of_float::value == 2 ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( mpl::is_void_< index_of_char >::value ));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user