apply_operation.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_APPLY_OPERATION_HPP
  9. #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_APPLY_OPERATION_HPP
  10. #include <boost/gil/detail/mp11.hpp>
  11. #include <boost/variant/apply_visitor.hpp>
  12. #ifdef BOOST_GIL_DOXYGEN_ONLY
  13. #undef BOOST_GIL_REDUCE_CODE_BLOAT
  14. #endif
  15. // Implements apply_operation for variants.
  16. // Optionally performs type reduction.
  17. #ifdef BOOST_GIL_REDUCE_CODE_BLOAT
  18. #include <boost/gil/extension/dynamic_image/reduce.hpp>
  19. #else
  20. namespace boost { namespace gil {
  21. /// \ingroup Variant
  22. /// \brief Invokes a generic mutable operation (represented as a unary function object) on a variant
  23. template <typename Types, typename UnaryOp>
  24. BOOST_FORCEINLINE
  25. auto apply_operation(variant<Types>& arg, UnaryOp op)
  26. #if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
  27. -> typename UnaryOp::result_type
  28. #endif
  29. {
  30. return apply_visitor(op, arg);
  31. }
  32. /// \ingroup Variant
  33. /// \brief Invokes a generic constant operation (represented as a unary function object) on a variant
  34. template <typename Types, typename UnaryOp>
  35. BOOST_FORCEINLINE
  36. auto apply_operation(variant<Types> const& arg, UnaryOp op)
  37. #if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
  38. -> typename UnaryOp::result_type
  39. #endif
  40. {
  41. return apply_visitor(op, arg);
  42. }
  43. /// \ingroup Variant
  44. /// \brief Invokes a generic constant operation (represented as a binary function object) on two variants
  45. template <typename Types1, typename Types2, typename BinaryOp>
  46. BOOST_FORCEINLINE
  47. auto apply_operation(
  48. variant<Types1> const& arg1,
  49. variant<Types2> const& arg2,
  50. BinaryOp op)
  51. #if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
  52. -> typename BinaryOp::result_type
  53. #endif
  54. {
  55. return apply_visitor(op, arg1, arg2);
  56. }
  57. }} // namespace boost::gil
  58. #endif // defined(BOOST_GIL_REDUCE_CODE_BLOAT)
  59. #endif