index_if.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef BOOST_MPL_INDEX_IF_HPP_INCLUDED
  2. #define BOOST_MPL_INDEX_IF_HPP_INCLUDED
  3. // Copyright Eric Friedman 2003
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/aux_/find_if_pred.hpp>
  14. #include <boost/mpl/begin_end.hpp>
  15. #include <boost/mpl/if.hpp>
  16. #include <boost/mpl/int.hpp>
  17. #include <boost/mpl/iter_fold_if.hpp>
  18. #include <boost/mpl/next.hpp>
  19. #include <boost/mpl/void.hpp>
  20. #include <boost/mpl/aux_/na_spec.hpp>
  21. #include <boost/mpl/aux_/lambda_support.hpp>
  22. #include <boost/type_traits/is_same.hpp>
  23. namespace boost { namespace mpl {
  24. template<
  25. typename BOOST_MPL_AUX_NA_PARAM(Sequence)
  26. , typename BOOST_MPL_AUX_NA_PARAM(Predicate)
  27. >
  28. struct index_if
  29. {
  30. typedef typename iter_fold_if<
  31. Sequence
  32. , int_<0>
  33. , next<>
  34. , aux::find_if_pred<Predicate>
  35. >::type result_;
  36. typedef typename end<Sequence>::type not_found_;
  37. typedef typename first<result_>::type result_index_;
  38. typedef typename second<result_>::type result_iterator_;
  39. typedef typename if_<
  40. is_same< result_iterator_,not_found_ >
  41. , void_
  42. , result_index_
  43. >::type type;
  44. BOOST_MPL_AUX_LAMBDA_SUPPORT(2,index_if,(Sequence,Predicate))
  45. };
  46. BOOST_MPL_AUX_NA_SPEC(2, index_if)
  47. }}
  48. #endif // BOOST_MPL_INDEX_IF_HPP_INCLUDED