]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/optional/sfinae_friendly_metafunctions.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / example / optional / sfinae_friendly_metafunctions.cpp
1 // Copyright Louis Dionne 2013-2016
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/not.hpp>
7 #include <boost/hana/optional.hpp>
8 #include <boost/hana/traits.hpp>
9 #include <boost/hana/type.hpp>
10
11 #include <type_traits>
12 #include <utility>
13 namespace hana = boost::hana;
14
15
16 template <typename ...>
17 using void_t = void;
18
19 template <typename T, typename = void>
20 struct has_type : std::false_type { };
21
22 template <typename T>
23 struct has_type<T, void_t<typename T::type>>
24 : std::true_type
25 { };
26
27 auto common_type_impl = hana::sfinae([](auto t, auto u) -> decltype(hana::type_c<
28 decltype(true ? hana::traits::declval(t) : hana::traits::declval(u))
29 >) { return {}; });
30
31 template <typename T, typename U>
32 using common_type2 = decltype(common_type_impl(hana::type_c<T>, hana::type_c<U>));
33
34 static_assert(!has_type<common_type2<int, int*>>{}, "");
35 static_assert(std::is_same<common_type2<int, float>::type, float>{}, "");
36
37 int main() { }