Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:05

0001 /*!
0002 @file
0003 Forward declares `boost::hana::value`.
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_FWD_VALUE_HPP
0011 #define BOOST_HANA_FWD_VALUE_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 
0016 
0017 namespace boost { namespace hana {
0018     //! Return the compile-time value associated to a constant.
0019     //! @ingroup group-Constant
0020     //!
0021     //! This function returns the value associated to a `Constant`. That
0022     //! value is always a constant expression. The normal way of using
0023     //! `value` on an object `c` is
0024     //! @code
0025     //!     constexpr auto result = hana::value<decltype(c)>();
0026     //! @endcode
0027     //!
0028     //! However, for convenience, an overload of `value` is provided so that
0029     //! it can be called as:
0030     //! @code
0031     //!     constexpr auto result = hana::value(c);
0032     //! @endcode
0033     //!
0034     //! This overload works by taking a `const&` to its argument, and then
0035     //! forwarding to the first version of `value`. Since it does not use
0036     //! its argument, the result can still be a constant expression, even
0037     //! if the argument is not a constant expression.
0038     //!
0039     //! @note
0040     //! `value<T>()` is tag-dispatched as `value_impl<C>::%apply<T>()`, where
0041     //! `C` is the tag of `T`.
0042     //!
0043     //! @note
0044     //! `hana::value` is an overloaded function, not a function object.
0045     //! Hence, it can't be passed to higher-order algorithms. If you need
0046     //! an equivalent function object, use `hana::value_of` instead.
0047     //!
0048     //!
0049     //! Example
0050     //! -------
0051     //! @include example/value.cpp
0052 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0053     template <typename T>
0054     constexpr auto value = []() -> decltype(auto) {
0055         return tag-dispatched;
0056     };
0057 #else
0058     template <typename C, typename = void>
0059     struct value_impl : value_impl<C, when<true>> { };
0060 
0061     template <typename T>
0062     constexpr decltype(auto) value();
0063 
0064     template <typename T>
0065     constexpr decltype(auto) value(T const&)
0066     { return hana::value<T>(); }
0067 #endif
0068 
0069     //! Equivalent to `value`, but can be passed to higher-order algorithms.
0070     //! @ingroup group-Constant
0071     //!
0072     //! This function object is equivalent to `value`, except it can be passed
0073     //! to higher order algorithms because it is a function object. `value`
0074     //! can't be passed to higher-order algorithms because it is implemented
0075     //! as an overloaded function.
0076     //!
0077     //! @note
0078     //! This function is a simple alias to `value`, and hence it is not
0079     //! tag-dispatched and can't be customized.
0080     //!
0081     //!
0082     //! Example
0083     //! -------
0084     //! @include example/value_of.cpp
0085 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0086     constexpr auto value_of = [](auto const& c) -> decltype(auto) {
0087         return hana::value(c);
0088     };
0089 #else
0090     struct value_of_t {
0091         template <typename T>
0092         constexpr decltype(auto) operator()(T const&) const
0093         { return hana::value<T>(); }
0094     };
0095 
0096     BOOST_HANA_INLINE_VARIABLE constexpr value_of_t value_of{};
0097 #endif
0098 }} // end namespace boost::hana
0099 
0100 #endif // !BOOST_HANA_FWD_VALUE_HPP