replace_if.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(FUSION_REPLACE_IF_08182005_0939)
  7. #define FUSION_REPLACE_IF_08182005_0939
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/view/transform_view/transform_view.hpp>
  10. #include <boost/fusion/algorithm/transformation/detail/replace_if.hpp>
  11. #include <boost/fusion/support/is_sequence.hpp>
  12. #include <boost/utility/enable_if.hpp>
  13. #include <boost/type_traits/is_same.hpp>
  14. namespace boost { namespace fusion
  15. {
  16. namespace result_of
  17. {
  18. template <typename Sequence, typename F, typename T>
  19. struct replace_if
  20. {
  21. typedef transform_view<Sequence, detail::replacer_if<F, T> > type;
  22. };
  23. }
  24. template <typename Sequence, typename F, typename T>
  25. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  26. inline typename
  27. enable_if<
  28. traits::is_sequence<Sequence>
  29. , typename result_of::replace_if<Sequence const, F, T>::type
  30. >::type
  31. replace_if(Sequence const& seq, F pred, T const& new_value)
  32. {
  33. typedef typename result_of::replace_if<Sequence const, F, T>::type result;
  34. detail::replacer_if<F, T> f(pred, new_value);
  35. return result(seq, f);
  36. }
  37. }}
  38. #endif