• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2 @file
3 Defines `BOOST_HANA_DISPATCH_IF`.
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_DETAIL_DISPATCH_IF_HPP
11 #define BOOST_HANA_DETAIL_DISPATCH_IF_HPP
12 
13 #include <boost/hana/config.hpp>
14 
15 #include <type_traits>
16 
17 
18 BOOST_HANA_NAMESPACE_BEGIN
19     struct deleted_implementation {
20         template <typename ...T>
21         static constexpr auto apply(T&& ...) = delete;
22     };
23 
24     //! @ingroup group-details
25     //! Dispatch to the given implementation method only when a condition is
26     //! satisfied.
27     //!
28     //! If the condition is satisfied, this macro is equivalent to the type
29     //! `IMPL`. Otherwise, it is equivalent to a type with a deleted static
30     //! function named `apply`. When a tag-dispatching error happens, the
31     //! condition should be false and the deleted static function `apply`
32     //! will prevent the compiler from generating too much garbage.
33     //!
34     //! @note
35     //! When `BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS` is defined, the
36     //! condition is always ignored and this macro expands to the
37     //! implementation only.
38     //!
39     //! @remark
40     //! This must be implemented as a macro, because we don't want the
41     //! condition to be evaluated at all when
42     //! `BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS` is defined.
43 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
44     #define BOOST_HANA_DISPATCH_IF(IMPL, ...)                               \
45         ::std::conditional_t<                                               \
46             (__VA_ARGS__),                                                  \
47             IMPL,                                                           \
48             ::boost::hana::deleted_implementation                           \
49         >                                                                   \
50     /**/
51 #else
52     #define BOOST_HANA_DISPATCH_IF(IMPL, ...) IMPL
53 #endif
54 BOOST_HANA_NAMESPACE_END
55 
56 #endif // !BOOST_HANA_DETAIL_DISPATCH_IF_HPP
57