replace_if.hpp 1.8 KB

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