Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/hana/fwd/core/when.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*!
0002 @file
0003 Forward declares `boost::hana::when` and `boost::hana::when_valid`.
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_CORE_WHEN_HPP
0011 #define BOOST_HANA_FWD_CORE_WHEN_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 
0015 
0016 namespace boost { namespace hana {
0017     //! @ingroup group-core
0018     //! Enable a partial specialization only if a boolean condition is true.
0019     //!
0020     //! You might also want to take a look at `when_valid`, which provides
0021     //! similar functionality but enables a specialziation only when some
0022     //! expression is well-formed.
0023     //!
0024     //! > #### Rationale for using `when` instead of `std::enable_if`
0025     //! > `when` is used to control the priority of partial specializations
0026     //! > in a finer grained manner than what can be achieved with the usual
0027     //! > `typename Enable = void` and `std::enable_if` pattern. For example,
0028     //! > a partially specialized tag-dispatched method will have a higher
0029     //! > priority than an equivalent specialization that uses `when`. For
0030     //! > more details, see the tutorial section on [tag-dispatching][1].
0031     //!
0032     //!
0033     //! Example
0034     //! -------
0035     //! @include example/core/when.cpp
0036     //!
0037     //! [1]: @ref tutorial-core-tag_dispatching
0038     template <bool condition>
0039     struct when;
0040 
0041     namespace core_detail {
0042         template <typename ...>
0043         struct always_true { static constexpr bool value = true; };
0044     }
0045 
0046     //! @ingroup group-core
0047     //! Variant of `when` allowing specializations to be enabled only if an
0048     //! expression is well-formed.
0049     //!
0050     //! `when_valid<...>` is always equivalent to `when<true>`. However, when
0051     //! used inside a partial specialization, SFINAE will cause the partial
0052     //! specialization to be ignored when the expression is ill-formed.
0053     //!
0054     //!
0055     //! Example
0056     //! -------
0057     //! @include example/core/when_valid.cpp
0058     //!
0059     //!
0060     //! @bug
0061     //! Using `when_valid` seems to trigger ambiguous partial specializations
0062     //! on GCC.
0063 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0064     template <typename ...>
0065     using when_valid = when<true>;
0066 #else
0067     template <typename ...Dummy>
0068     using when_valid = when<
0069         core_detail::always_true<Dummy...>::value
0070     >;
0071 #endif
0072 }} // end namespace boost::hana
0073 
0074 #endif // !BOOST_HANA_FWD_CORE_WHEN_HPP