Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / hana / functional / id.hpp
1 /*!
2 @file
3 Defines `boost::hana::id`.
4
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8  */
9
10 #ifndef BOOST_HANA_FUNCTIONAL_ID_HPP
11 #define BOOST_HANA_FUNCTIONAL_ID_HPP
12
13 #include <boost/hana/config.hpp>
14
15
16 BOOST_HANA_NAMESPACE_BEGIN
17     //! @ingroup group-functional
18     //! The identity function -- returns its argument unchanged.
19     //!
20     //! ### Example
21     //! @include example/functional/id.cpp
22 #ifdef BOOST_HANA_DOXYGEN_INVOKED
23     constexpr auto id = [](auto&& x) -> decltype(auto) {
24         return forwarded(x);
25     };
26 #else
27     struct id_t {
28         template <typename T>
29         constexpr T operator()(T&& t) const {
30             return static_cast<T&&>(t);
31         }
32     };
33
34     constexpr id_t id{};
35 #endif
36 BOOST_HANA_NAMESPACE_END
37
38 #endif // !BOOST_HANA_FUNCTIONAL_ID_HPP