9
3

decay.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*=============================================================================
  2. Copyright (c) 2015 Paul Fultz II
  3. decay.h
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_HOF_GUARD_DECAY_H
  8. #define BOOST_HOF_GUARD_DECAY_H
  9. /// decay
  10. /// =====
  11. ///
  12. /// Description
  13. /// -----------
  14. ///
  15. /// The `decay` function is a unary function object that returns whats given to it after decaying its type.
  16. ///
  17. /// Synopsis
  18. /// --------
  19. ///
  20. /// struct
  21. /// {
  22. /// template<class T>
  23. /// constexpr typename decay<T>::type operator()(T&& x) const
  24. /// {
  25. /// return boost::hof::forward<T>(x);
  26. /// }
  27. /// } decay;
  28. ///
  29. /// References
  30. /// ----------
  31. ///
  32. /// * [n3255](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3255.html) - Proposal for `decay_copy`
  33. ///
  34. #include <boost/hof/detail/delegate.hpp>
  35. #include <boost/hof/detail/unwrap.hpp>
  36. #include <boost/hof/detail/static_const_var.hpp>
  37. #include <boost/hof/detail/forward.hpp>
  38. namespace boost { namespace hof { namespace detail {
  39. template<class T>
  40. struct decay_mf
  41. : unwrap_reference<typename std::decay<T>::type>
  42. {};
  43. struct decay_f
  44. {
  45. template<
  46. class T,
  47. class Result=typename unwrap_reference<typename std::decay<T>::type>::type,
  48. class=typename std::enable_if<(BOOST_HOF_IS_CONSTRUCTIBLE(Result, T))>::type
  49. >
  50. constexpr Result operator()(T&& x) const BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(Result, T&&)
  51. {
  52. return BOOST_HOF_FORWARD(T)(x);
  53. }
  54. };
  55. }
  56. BOOST_HOF_DECLARE_STATIC_VAR(decay, detail::decay_f);
  57. }} // namespace boost::hof
  58. #endif