Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:15

0001 /*=============================================================================
0002     Copyright (c) 2012 Paul Fultz II
0003     identity.h
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 
0008 #ifndef BOOST_HOF_GUARD_FUNCTION_IDENTITY_H
0009 #define BOOST_HOF_GUARD_FUNCTION_IDENTITY_H
0010 
0011 /// identity
0012 /// ========
0013 /// 
0014 /// Description
0015 /// -----------
0016 /// 
0017 /// The `identity` function is an unary function object that returns whats given to it. 
0018 /// 
0019 /// Semantics
0020 /// ---------
0021 /// 
0022 ///     assert(identity(x) == x);
0023 /// 
0024 /// Synopsis
0025 /// --------
0026 /// 
0027 ///     template<class T>
0028 ///     constexpr T identity(T&& x);
0029 /// 
0030 
0031 #include <utility>
0032 #include <initializer_list>
0033 #include <boost/hof/detail/forward.hpp>
0034 #include <boost/hof/detail/static_const_var.hpp>
0035 
0036 namespace boost { namespace hof { namespace identity_detail {
0037 
0038 struct identity_base
0039 {
0040     template<class T>
0041     constexpr T operator()(T&& x) const 
0042     noexcept(std::is_reference<T>::value || BOOST_HOF_IS_NOTHROW_MOVE_CONSTRUCTIBLE(T))
0043     {
0044         return BOOST_HOF_FORWARD(T)(x);
0045     }
0046 
0047     template<class T>
0048     constexpr std::initializer_list<T>& operator()(std::initializer_list<T>& x) const noexcept
0049     {
0050         return x;
0051     }
0052 
0053     template<class T>
0054     constexpr const std::initializer_list<T>& operator()(const std::initializer_list<T>& x) const noexcept
0055     {
0056         return x;
0057     }
0058 
0059     template<class T>
0060     constexpr std::initializer_list<T> operator()(std::initializer_list<T>&& x) const noexcept(noexcept(std::initializer_list<T>(std::move(x))))
0061     {
0062         return BOOST_HOF_FORWARD(std::initializer_list<T>)(x);
0063     }
0064 };
0065 
0066 }
0067 
0068 BOOST_HOF_DECLARE_STATIC_VAR(identity, identity_detail::identity_base);
0069 
0070 }} // namespace boost::hof
0071 
0072 #endif