apply_operation.hpp 2.0 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/variant/apply_visitor.hpp>
  11. #ifdef BOOST_GIL_DOXYGEN_ONLY
  12. #undef BOOST_GIL_REDUCE_CODE_BLOAT
  13. #endif
  14. // Implements apply_operation for variants.
  15. // Optionally performs type reduction.
  16. #ifdef BOOST_GIL_REDUCE_CODE_BLOAT
  17. #include <boost/gil/extension/dynamic_image/reduce.hpp>
  18. #else
  19. namespace boost { namespace gil {
  20. /// \ingroup Variant
  21. /// \brief Invokes a generic mutable operation (represented as a unary function object) on a variant
  22. template <typename Types, typename UnaryOp>
  23. BOOST_FORCEINLINE
  24. auto apply_operation(variant<Types>& arg, UnaryOp op)
  25. #if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
  26. -> typename UnaryOp::result_type
  27. #endif
  28. {
  29. return apply_visitor(op, arg);
  30. }
  31. /// \ingroup Variant
  32. /// \brief Invokes a generic constant operation (represented as a unary function object) on a variant
  33. template <typename Types, typename UnaryOp>
  34. BOOST_FORCEINLINE
  35. auto apply_operation(variant<Types> const& arg, UnaryOp op)
  36. #if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
  37. -> typename UnaryOp::result_type
  38. #endif
  39. {
  40. return apply_visitor(op, arg);
  41. }
  42. /// \ingroup Variant
  43. /// \brief Invokes a generic constant operation (represented as a binary function object) on two variants
  44. template <typename Types1, typename Types2, typename BinaryOp>
  45. BOOST_FORCEINLINE
  46. auto apply_operation(
  47. variant<Types1> const& arg1,
  48. variant<Types2> const& arg2,
  49. BinaryOp op)
  50. #if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
  51. -> typename BinaryOp::result_type
  52. #endif
  53. {
  54. return apply_visitor(
  55. op, arg1, arg2);
  56. }
  57. }} // namespace boost::gil
  58. #endif // defined(BOOST_GIL_REDUCE_CODE_BLOAT)
  59. #endif