1// Copyright Louis Dionne 2013-2022
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>
14namespace hana = boost::hana;
15
16
17template <typename ...>
18using void_t = void;
19
20template <typename T, typename = void>
21struct has_type : std::false_type { };
22
23template <typename T>
24struct has_type<T, void_t<typename T::type>>
25 : std::true_type
26{ };
27
28auto 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
32template <typename T, typename U>
33using common_type = decltype(common_type_impl(hana::type_c<T>, hana::type_c<U>));
34
35BOOST_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
41static_assert(!has_type<common_type<int, int*>>{}, "");
42static_assert(std::is_same<common_type<int, float>::type, float>{}, "");
43
44int main() { }
45

source code of boost/libs/hana/example/optional/sfinae_friendly_metafunctions.cpp