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 
8 #ifndef BOOST_HOF_GUARD_DECAY_H
9 #define BOOST_HOF_GUARD_DECAY_H
10 
11 /// decay
12 /// =====
13 ///
14 /// Description
15 /// -----------
16 ///
17 /// The `decay` function is a unary function object that returns whats given to it after decaying its type.
18 ///
19 /// Synopsis
20 /// --------
21 ///
22 ///     struct
23 ///     {
24 ///         template<class T>
25 ///         constexpr typename decay<T>::type operator()(T&& x) const
26 ///         {
27 ///             return boost::hof::forward<T>(x);
28 ///         }
29 ///     } decay;
30 ///
31 /// References
32 /// ----------
33 ///
34 /// * [n3255](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3255.html) - Proposal for `decay_copy`
35 ///
36 
37 #include <boost/hof/detail/delegate.hpp>
38 #include <boost/hof/detail/unwrap.hpp>
39 #include <boost/hof/detail/static_const_var.hpp>
40 #include <boost/hof/detail/forward.hpp>
41 
42 namespace boost { namespace hof { namespace detail {
43 
44 template<class T>
45 struct decay_mf
46 : unwrap_reference<typename std::decay<T>::type>
47 {};
48 
49 struct decay_f
50 {
51     template<
52         class T,
53         class Result=typename unwrap_reference<typename std::decay<T>::type>::type,
54         class=typename std::enable_if<(BOOST_HOF_IS_CONSTRUCTIBLE(Result, T))>::type
55     >
operator ()boost::hof::detail::decay_f56     constexpr Result operator()(T&& x) const BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(Result, T&&)
57     {
58         return BOOST_HOF_FORWARD(T)(x);
59     }
60 };
61 
62 }
63 
64 BOOST_HOF_DECLARE_STATIC_VAR(decay, detail::decay_f);
65 
66 }} // namespace boost::hof
67 
68 #endif
69