copy_if.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef BOOST_MPL_COPY_IF_HPP_INCLUDED
  2. #define BOOST_MPL_COPY_IF_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. // Copyright David Abrahams 2003-2004
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. #include <boost/mpl/fold.hpp>
  15. #include <boost/mpl/reverse_fold.hpp>
  16. #include <boost/mpl/apply.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/identity.hpp>
  19. #include <boost/mpl/protect.hpp>
  20. #include <boost/mpl/aux_/inserter_algorithm.hpp>
  21. #include <boost/mpl/aux_/config/forwarding.hpp>
  22. namespace boost { namespace mpl {
  23. namespace aux {
  24. template<
  25. typename Operation
  26. , typename Predicate
  27. >
  28. struct copy_if_op
  29. {
  30. template< typename Sequence, typename T > struct apply
  31. #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
  32. : eval_if<
  33. typename apply1<Predicate,T>::type
  34. , apply2<Operation,Sequence,T>
  35. , identity<Sequence>
  36. >
  37. {
  38. #else
  39. {
  40. typedef typename eval_if<
  41. typename apply1<Predicate,T>::type
  42. , apply2<Operation,Sequence,T>
  43. , identity<Sequence>
  44. >::type type;
  45. #endif
  46. };
  47. };
  48. template<
  49. typename Sequence
  50. , typename Predicate
  51. , typename Inserter
  52. >
  53. struct copy_if_impl
  54. : fold<
  55. Sequence
  56. , typename Inserter::state
  57. , protect< aux::copy_if_op<
  58. typename Inserter::operation
  59. , Predicate
  60. > >
  61. >
  62. {
  63. };
  64. template<
  65. typename Sequence
  66. , typename Predicate
  67. , typename Inserter
  68. >
  69. struct reverse_copy_if_impl
  70. : reverse_fold<
  71. Sequence
  72. , typename Inserter::state
  73. , protect< aux::copy_if_op<
  74. typename Inserter::operation
  75. , Predicate
  76. > >
  77. >
  78. {
  79. };
  80. } // namespace aux
  81. BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(3, copy_if)
  82. }}
  83. #endif // BOOST_MPL_COPY_IF_HPP_INCLUDED