Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:58

0001 /*!
0002 @file
0003 Defines `boost::hana::always`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FUNCTIONAL_ALWAYS_HPP
0011 #define BOOST_HANA_FUNCTIONAL_ALWAYS_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/detail/create.hpp>
0015 
0016 #include <utility>
0017 
0018 
0019 namespace boost { namespace hana {
0020     //! @ingroup group-functional
0021     //! Return a constant function returning `x` regardless of the
0022     //! argument(s) it is invoked with.
0023     //!
0024     //! Specifically, `always(x)` is a function such that
0025     //! @code
0026     //!     always(x)(y...) == x
0027     //! @endcode
0028     //! for any `y...`. A copy of `x` is made and it is owned by the
0029     //! `always(x)` function. When `always(x)` is called, it will return
0030     //! a reference to the `x` it owns. This reference is valid as long
0031     //! as `always(x)` is in scope.
0032     //!
0033     //!
0034     //! ### Example
0035     //! @include example/functional/always.cpp
0036 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0037     constexpr auto always = [](auto&& x) {
0038         return [perfect-capture](auto const& ...y) -> decltype(auto) {
0039             return forwarded(x);
0040         };
0041     };
0042 #else
0043     template <typename T>
0044     struct _always {
0045         T val_;
0046 
0047         template <typename ...Args>
0048         constexpr T const& operator()(Args const& ...) const&
0049         { return val_; }
0050 
0051         template <typename ...Args>
0052         constexpr T& operator()(Args const& ...) &
0053         { return val_; }
0054 
0055         template <typename ...Args>
0056         constexpr T operator()(Args const& ...) &&
0057         { return std::move(val_); }
0058     };
0059 
0060     BOOST_HANA_INLINE_VARIABLE constexpr detail::create<_always> always{};
0061 #endif
0062 }} // end namespace boost::hana
0063 
0064 #endif // !BOOST_HANA_FUNCTIONAL_ALWAYS_HPP