Skip to content

Commit ca5a5b3

Browse files
committed
[WIP] Make sure core metafunctions return IntegralConstants
This does not work, because we would need to include the full definition of hana::integral_constant in core metafunctions, and that introduces circular dependencies.
1 parent 9fe9d2f commit ca5a5b3

File tree

7 files changed

+25
-12
lines changed

7 files changed

+25
-12
lines changed

Diff for: include/boost/hana/core/common.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ Distributed under the Boost Software License, Version 1.0.
1616
#include <boost/hana/config.hpp>
1717
#include <boost/hana/core/when.hpp>
1818
#include <boost/hana/detail/canonical_constant.hpp>
19+
#include <boost/hana/detail/integral_constant.hpp>
1920
#include <boost/hana/detail/std_common_type.hpp>
2021
#include <boost/hana/detail/void_t.hpp>
2122

22-
#include <type_traits>
23-
2423

2524
BOOST_HANA_NAMESPACE_BEGIN
2625
//////////////////////////////////////////////////////////////////////////
@@ -45,11 +44,11 @@ BOOST_HANA_NAMESPACE_BEGIN
4544
// has_common
4645
//////////////////////////////////////////////////////////////////////////
4746
template <typename T, typename U, typename>
48-
struct has_common : std::false_type { };
47+
struct has_common : hana::integral_constant<bool, false> { };
4948

5049
template <typename T, typename U>
5150
struct has_common<T, U, detail::void_t<typename common<T, U>::type>>
52-
: std::true_type
51+
: hana::integral_constant<bool, true>
5352
{ };
5453

5554
//////////////////////////////////////////////////////////////////////////

Diff for: include/boost/hana/core/default.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ Distributed under the Boost Software License, Version 1.0.
1313
#include <boost/hana/fwd/core/default.hpp>
1414

1515
#include <boost/hana/config.hpp>
16-
17-
#include <type_traits>
16+
#include <boost/hana/detail/integral_constant.hpp>
1817

1918

2019
BOOST_HANA_NAMESPACE_BEGIN
2120
template <typename Method, typename>
22-
struct is_default : std::false_type { };
21+
struct is_default : hana::integral_constant<bool, false> { };
2322

2423
template <typename Method>
2524
struct is_default<Method, decltype((void)
2625
static_cast<default_>(*(Method*)0)
2726
)>
28-
: std::true_type
27+
: hana::integral_constant<bool, true>
2928
{ };
3029
BOOST_HANA_NAMESPACE_END
3130

Diff for: include/boost/hana/core/to.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Distributed under the Boost Software License, Version 1.0.
1919
#include <boost/hana/core/common.hpp>
2020
#include <boost/hana/core/dispatch.hpp>
2121
#include <boost/hana/core/make.hpp>
22+
#include <boost/hana/detail/integral_constant.hpp>
2223
#include <boost/hana/detail/wrong.hpp>
2324
#include <boost/hana/unpack.hpp>
2425
#include <boost/hana/value.hpp>
@@ -146,23 +147,23 @@ BOOST_HANA_NAMESPACE_BEGIN
146147
// is_convertible
147148
//////////////////////////////////////////////////////////////////////////
148149
template <typename From, typename To, typename>
149-
struct is_convertible : std::true_type { };
150+
struct is_convertible : hana::integral_constant<bool, true> { };
150151

151152
template <typename From, typename To>
152153
struct is_convertible<From, To, decltype((void)
153154
static_cast<convert_detail::no_conversion>(*(to_impl<To, From>*)0)
154-
)> : std::false_type { };
155+
)> : hana::integral_constant<bool, false> { };
155156

156157
//////////////////////////////////////////////////////////////////////////
157158
// is_embedded
158159
//////////////////////////////////////////////////////////////////////////
159160
template <typename From, typename To, typename>
160-
struct is_embedded : std::false_type { };
161+
struct is_embedded : hana::integral_constant<bool, false> { };
161162

162163
template <typename From, typename To>
163164
struct is_embedded<From, To, decltype((void)
164165
static_cast<embedding<true>>(*(to_impl<To, From>*)0)
165-
)> : std::true_type { };
166+
)> : hana::integral_constant<bool, true> { };
166167

167168
//////////////////////////////////////////////////////////////////////////
168169
// Conversion for Constants

Diff for: test/core/common.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Distributed under the Boost Software License, Version 1.0.
33
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
44

5+
#include <boost/hana/concept/integral_constant.hpp>
56
#include <boost/hana/core/common.hpp>
7+
#include <boost/hana/not.hpp>
68

79
#include <type_traits>
810
namespace hana = boost::hana;
@@ -29,4 +31,6 @@ static_assert(!hana::has_common<T, void>{}, "");
2931
static_assert(!hana::has_common<invalid, T>{}, "");
3032
static_assert(!hana::has_common<T, invalid>{}, "");
3133

34+
static_assert(hana::IntegralConstant<hana::has_common<T, T>>{}, "");
35+
3236
int main() { }

Diff for: test/core/default.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
44

55
#include <boost/hana/core/default.hpp>
6+
7+
#include <boost/hana/concept/integral_constant.hpp>
68
namespace hana = boost::hana;
79

810

@@ -15,4 +17,6 @@ struct method_impl<int> { };
1517
static_assert(hana::is_default<method_impl<void>>{}, "");
1618
static_assert(!hana::is_default<method_impl<int>>{}, "");
1719

20+
static_assert(hana::IntegralConstant<hana::is_default<method_impl<void>>>{}, "");
21+
1822
int main() { }

Diff for: test/core/is_embedded.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// Distributed under the Boost Software License, Version 1.0.
33
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
44

5+
#include <boost/hana/concept/integral_constant.hpp>
56
#include <boost/hana/core/to.hpp>
67
#include <boost/hana/equal.hpp>
78

89
#include <climits>
910
namespace hana = boost::hana;
1011

1112

13+
static_assert(hana::IntegralConstant<hana::is_embedded<float, double>>{}, "");
14+
1215
// This test makes sure that fundamental types are properly embedded in
1316
// each other, when sensible.
1417

Diff for: test/core/to.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <boost/hana/core/to.hpp>
66

77
#include <boost/hana/assert.hpp>
8+
#include <boost/hana/concept/integral_constant.hpp>
89
#include <boost/hana/core/tag_of.hpp>
910

1011
#include <string>
@@ -103,4 +104,6 @@ int main() {
103104

104105
static_assert(hana::is_convertible<int, void>{}, "");
105106
static_assert(!hana::is_embedded<int, void>{}, "");
107+
108+
static_assert(hana::IntegralConstant<hana::is_convertible<int, void>>{}, "");
106109
}

0 commit comments

Comments
 (0)