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/core/tag_of.hpp>
6#include <boost/hana/core/when.hpp>
7
8#include <type_traits>
9namespace hana = boost::hana;
10
11
12template <typename T, typename ExpectedDatatype>
13struct test {
14 static_assert(std::is_same<hana::tag_of_t<T>, ExpectedDatatype>::value, "");
15 static_assert(std::is_same<hana::tag_of_t<T const>, ExpectedDatatype>::value, "");
16 static_assert(std::is_same<hana::tag_of_t<T volatile>, ExpectedDatatype>::value, "");
17 static_assert(std::is_same<hana::tag_of_t<T const volatile>, ExpectedDatatype>::value, "");
18
19 static_assert(std::is_same<hana::tag_of_t<T&>, ExpectedDatatype>::value, "");
20 static_assert(std::is_same<hana::tag_of_t<T const&>, ExpectedDatatype>::value, "");
21 static_assert(std::is_same<hana::tag_of_t<T volatile&>, ExpectedDatatype>::value, "");
22 static_assert(std::is_same<hana::tag_of_t<T const volatile&>, ExpectedDatatype>::value, "");
23
24 static_assert(std::is_same<hana::tag_of_t<T&&>, ExpectedDatatype>::value, "");
25 static_assert(std::is_same<hana::tag_of_t<T const&&>, ExpectedDatatype>::value, "");
26 static_assert(std::is_same<hana::tag_of_t<T volatile&&>, ExpectedDatatype>::value, "");
27 static_assert(std::is_same<hana::tag_of_t<T const volatile&&>, ExpectedDatatype>::value, "");
28};
29
30struct NestedDatatype;
31struct Nested { struct hana_tag; };
32template struct test<Nested, Nested::hana_tag>;
33
34struct NoNestedDatatype { };
35template struct test<NoNestedDatatype, NoNestedDatatype>;
36
37struct NoNestedHana { };
38template struct test<NoNestedHana, NoNestedHana>;
39
40
41struct FullySpecializedDatatype;
42struct FullySpecialized;
43namespace boost { namespace hana {
44 template <>
45 struct tag_of<FullySpecialized> {
46 using type = FullySpecializedDatatype;
47 };
48}}
49template struct test<FullySpecialized, FullySpecializedDatatype>;
50
51
52struct PartiallySpecializedDatatype;
53template <typename> struct PartiallySpecialized;
54namespace boost { namespace hana {
55 template <typename T>
56 struct tag_of<PartiallySpecialized<T>> {
57 using type = PartiallySpecializedDatatype;
58 };
59}}
60template struct test<PartiallySpecialized<struct anything>, PartiallySpecializedDatatype>;
61
62
63struct PredicatedDatatype;
64struct Predicated { static constexpr bool predicate = true; };
65namespace boost { namespace hana {
66 template <typename T>
67 struct tag_of<T, hana::when<T::predicate>> {
68 using type = PredicatedDatatype;
69 };
70}}
71template struct test<Predicated, PredicatedDatatype>;
72
73
74int main() { }
75

source code of boost/libs/hana/test/core/tag_of.cpp