1) 'Not found' result is void_; 2) Uses refactored find_if_pred.

[SVN r20714]
This commit is contained in:
Eric Friedman
2003-11-07 03:49:58 +00:00
parent d934b4944f
commit 4687267d09
2 changed files with 10 additions and 25 deletions

View File

@@ -18,18 +18,16 @@
#define BOOST_MPL_INDEX_IF_HPP_INCLUDED #define BOOST_MPL_INDEX_IF_HPP_INCLUDED
#include "boost/mpl/aux_/config/workaround.hpp" #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_fold_if_impl.hpp"
#include "boost/mpl/aux_/iter_apply.hpp"
#include "boost/mpl/always.hpp" #include "boost/mpl/always.hpp"
#include "boost/mpl/apply.hpp"
#include "boost/mpl/begin_end.hpp" #include "boost/mpl/begin_end.hpp"
#include "boost/mpl/bool.hpp" #include "boost/mpl/bool.hpp"
#include "boost/mpl/if.hpp" #include "boost/mpl/if.hpp"
#include "boost/mpl/int.hpp" #include "boost/mpl/int.hpp"
#include "boost/mpl/lambda.hpp" #include "boost/mpl/lambda.hpp"
#include "boost/mpl/next.hpp" #include "boost/mpl/next.hpp"
#include "boost/mpl/not.hpp" #include "boost/mpl/void.hpp"
#include "boost/mpl/or.hpp"
#include "boost/mpl/aux_/void_spec.hpp" #include "boost/mpl/aux_/void_spec.hpp"
#include "boost/mpl/aux_/lambda_support.hpp" #include "boost/mpl/aux_/lambda_support.hpp"
#include "boost/type_traits/is_same.hpp" #include "boost/type_traits/is_same.hpp"
@@ -39,21 +37,6 @@ namespace mpl {
namespace aux { 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 struct index_if_op
{ {
template < typename Index, typename Iterator > template < typename Index, typename Iterator >
@@ -88,7 +71,7 @@ struct index_if
first_ first_
, int_<0> , int_<0>
, aux::index_if_op , aux::index_if_op
, aux::index_if_pred<pred_,last_> , aux::find_if_pred<pred_,last_>
, void , void
, always<false_> , always<false_>
> >
@@ -104,7 +87,7 @@ struct index_if
public: public:
typedef typename if_< typedef typename if_<
is_same< result_iterator_,last_ > is_same< result_iterator_,last_ >
, int_<-1> , void_
, result_index_ , result_index_
>::type type; >::type type;

View File

@@ -18,6 +18,7 @@
#include "boost/static_assert.hpp" #include "boost/static_assert.hpp"
#include "boost/mpl/list.hpp" #include "boost/mpl/list.hpp"
#include "boost/mpl/void.hpp"
namespace mpl = boost::mpl; 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, float >::type index_of_float;
typedef mpl::index_of< types, char >::type index_of_char; typedef mpl::index_of< types, char >::type index_of_char;
BOOST_STATIC_ASSERT( index_of_int::value == 0 ); BOOST_STATIC_ASSERT(( index_of_int::value == 0 ));
BOOST_STATIC_ASSERT( index_of_double::value == 1 ); BOOST_STATIC_ASSERT(( index_of_double::value == 1 ));
BOOST_STATIC_ASSERT( index_of_float::value == 2 ); BOOST_STATIC_ASSERT(( index_of_float::value == 2 ));
BOOST_STATIC_ASSERT( index_of_char::value == -1 ); // 'not found'
BOOST_STATIC_ASSERT(( mpl::is_void_< index_of_char >::value ));
return 0; return 0;
} }