]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/optional/sfinae_friendly_metafunctions.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / example / optional / sfinae_friendly_metafunctions.cpp
1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/equal.hpp>
7 #include <boost/hana/not.hpp>
8 #include <boost/hana/optional.hpp>
9 #include <boost/hana/traits.hpp>
10 #include <boost/hana/type.hpp>
11
12 #include <type_traits>
13 #include <utility>
14 namespace hana = boost::hana;
15
16
17 template <typename ...>
18 using void_t = void;
19
20 template <typename T, typename = void>
21 struct has_type : std::false_type { };
22
23 template <typename T>
24 struct has_type<T, void_t<typename T::type>>
25 : std::true_type
26 { };
27
28 auto common_type_impl = hana::sfinae([](auto t, auto u) -> hana::type<
29 decltype(true ? hana::traits::declval(t) : hana::traits::declval(u))
30 > { return {}; });
31
32 template <typename T, typename U>
33 using common_type = decltype(common_type_impl(hana::type_c<T>, hana::type_c<U>));
34
35 BOOST_HANA_CONSTANT_CHECK(
36 common_type_impl(hana::type_c<int>, hana::type_c<float>)
37 ==
38 hana::just(hana::type_c<float>)
39 );
40
41 static_assert(!has_type<common_type<int, int*>>{}, "");
42 static_assert(std::is_same<common_type<int, float>::type, float>{}, "");
43
44 int main() { }