From fde5e427e1593bf5832ab5829fc4cbe4a3da0f1c Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Thu, 17 Nov 2016 09:07:07 +0100 Subject: [PATCH] [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. --- include/boost/hana/core/common.hpp | 7 +++---- include/boost/hana/core/default.hpp | 7 +++---- include/boost/hana/core/to.hpp | 9 +++++---- test/core/common.cpp | 4 ++++ test/core/default.cpp | 4 ++++ test/core/is_embedded.cpp | 3 +++ test/core/to.cpp | 3 +++ 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/boost/hana/core/common.hpp b/include/boost/hana/core/common.hpp index c32de77feb..b9a805be1b 100644 --- a/include/boost/hana/core/common.hpp +++ b/include/boost/hana/core/common.hpp @@ -16,11 +16,10 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include +#include #include #include -#include - BOOST_HANA_NAMESPACE_BEGIN ////////////////////////////////////////////////////////////////////////// @@ -45,11 +44,11 @@ BOOST_HANA_NAMESPACE_BEGIN // has_common ////////////////////////////////////////////////////////////////////////// template - struct has_common : std::false_type { }; + struct has_common : hana::integral_constant { }; template struct has_common::type>> - : std::true_type + : hana::integral_constant { }; ////////////////////////////////////////////////////////////////////////// diff --git a/include/boost/hana/core/default.hpp b/include/boost/hana/core/default.hpp index 45c70503c1..36883c0115 100644 --- a/include/boost/hana/core/default.hpp +++ b/include/boost/hana/core/default.hpp @@ -13,19 +13,18 @@ Distributed under the Boost Software License, Version 1.0. #include #include - -#include +#include BOOST_HANA_NAMESPACE_BEGIN template - struct is_default : std::false_type { }; + struct is_default : hana::integral_constant { }; template struct is_default(*(Method*)0) )> - : std::true_type + : hana::integral_constant { }; BOOST_HANA_NAMESPACE_END diff --git a/include/boost/hana/core/to.hpp b/include/boost/hana/core/to.hpp index 6a6a115b3a..aad6c733cf 100644 --- a/include/boost/hana/core/to.hpp +++ b/include/boost/hana/core/to.hpp @@ -19,6 +19,7 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include +#include #include #include #include @@ -146,23 +147,23 @@ BOOST_HANA_NAMESPACE_BEGIN // is_convertible ////////////////////////////////////////////////////////////////////////// template - struct is_convertible : std::true_type { }; + struct is_convertible : hana::integral_constant { }; template struct is_convertible(*(to_impl*)0) - )> : std::false_type { }; + )> : hana::integral_constant { }; ////////////////////////////////////////////////////////////////////////// // is_embedded ////////////////////////////////////////////////////////////////////////// template - struct is_embedded : std::false_type { }; + struct is_embedded : hana::integral_constant { }; template struct is_embedded>(*(to_impl*)0) - )> : std::true_type { }; + )> : hana::integral_constant { }; ////////////////////////////////////////////////////////////////////////// // Conversion for Constants diff --git a/test/core/common.cpp b/test/core/common.cpp index c3b24f9008..4ff79cbdfc 100644 --- a/test/core/common.cpp +++ b/test/core/common.cpp @@ -2,7 +2,9 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +#include #include +#include #include namespace hana = boost::hana; @@ -29,4 +31,6 @@ static_assert(!hana::has_common{}, ""); static_assert(!hana::has_common{}, ""); static_assert(!hana::has_common{}, ""); +static_assert(hana::IntegralConstant>{}, ""); + int main() { } diff --git a/test/core/default.cpp b/test/core/default.cpp index 9846c22b89..3b66e46ebd 100644 --- a/test/core/default.cpp +++ b/test/core/default.cpp @@ -3,6 +3,8 @@ // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) #include + +#include namespace hana = boost::hana; @@ -15,4 +17,6 @@ struct method_impl { }; static_assert(hana::is_default>{}, ""); static_assert(!hana::is_default>{}, ""); +static_assert(hana::IntegralConstant>>{}, ""); + int main() { } diff --git a/test/core/is_embedded.cpp b/test/core/is_embedded.cpp index 12a4409015..b17e74f26c 100644 --- a/test/core/is_embedded.cpp +++ b/test/core/is_embedded.cpp @@ -2,6 +2,7 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) +#include #include #include @@ -9,6 +10,8 @@ namespace hana = boost::hana; +static_assert(hana::IntegralConstant>{}, ""); + // This test makes sure that fundamental types are properly embedded in // each other, when sensible. diff --git a/test/core/to.cpp b/test/core/to.cpp index f4dd54ef70..c20068f21d 100644 --- a/test/core/to.cpp +++ b/test/core/to.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -103,4 +104,6 @@ int main() { static_assert(hana::is_convertible{}, ""); static_assert(!hana::is_embedded{}, ""); + + static_assert(hana::IntegralConstant>{}, ""); }