]>
git.proxmox.com Git - ceph.git/blob - 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)
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>
12 #include <type_traits>
14 namespace hana
= boost::hana
;
17 template <typename
...>
20 template <typename T
, typename
= void>
21 struct has_type
: std::false_type
{ };
24 struct has_type
<T
, void_t
<typename
T::type
>>
28 auto common_type_impl
= hana::sfinae([](auto t
, auto u
) -> hana::type
<
29 decltype(true ? hana::traits::declval(t
) : hana::traits::declval(u
))
32 template <typename T
, typename U
>
33 using common_type
= decltype(common_type_impl(hana::type_c
<T
>, hana::type_c
<U
>));
35 BOOST_HANA_CONSTANT_CHECK(
36 common_type_impl(hana::type_c
<int>, hana::type_c
<float>)
38 hana::just(hana::type_c
<float>)
41 static_assert(!has_type
<common_type
<int, int*>>{}, "");
42 static_assert(std::is_same
<common_type
<int, float>::type
, float>{}, "");