From 0171246a618f558934d48c392083513f2e995987 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 28 Oct 2022 01:47:27 +0300 Subject: [PATCH] Add is_described_class --- .../container_hash/is_described_class.hpp | 35 ++++++++++++ test/Jamfile.v2 | 5 ++ test/is_described_class_test.cpp | 56 +++++++++++++++++++ test/is_described_class_test2.cpp | 35 ++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 include/boost/container_hash/is_described_class.hpp create mode 100644 test/is_described_class_test.cpp create mode 100644 test/is_described_class_test2.cpp diff --git a/include/boost/container_hash/is_described_class.hpp b/include/boost/container_hash/is_described_class.hpp new file mode 100644 index 0000000..81f16d5 --- /dev/null +++ b/include/boost/container_hash/is_described_class.hpp @@ -0,0 +1,35 @@ +// Copyright 2022 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED +#define BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED + +#include +#include +#include + +namespace boost +{ +namespace container_hash +{ + +#if defined(BOOST_DESCRIBE_CXX11) + +template struct is_described_class: boost::integral_constant::value && describe::has_describe_members::value> +{ +}; + +#else + +template struct is_described_class: boost::false_type +{ +}; + +#endif + +} // namespace container_hash +} // namespace boost + +#endif // #ifndef BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e72f200..647f6dc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -102,3 +102,8 @@ run is_range_test3.cpp ; run is_contiguous_range_test2.cpp ; run is_unordered_range_test2.cpp ; run is_contiguous_range_test3.cpp ; + +run is_described_class_test.cpp + : : : extra ; +run is_described_class_test2.cpp + : : : extra ; diff --git a/test/is_described_class_test.cpp b/test/is_described_class_test.cpp new file mode 100644 index 0000000..66516ff --- /dev/null +++ b/test/is_described_class_test.cpp @@ -0,0 +1,56 @@ +// Copyright 2022 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include + +struct X1 +{ +}; + +struct X2 +{ + int m; +}; + +struct Y1 +{ +}; + +BOOST_DESCRIBE_STRUCT( Y1, (), () ) + +struct Y2: Y1 +{ + int m; +}; + +BOOST_DESCRIBE_STRUCT( Y2, (Y1), (m) ) + +int main() +{ + using boost::container_hash::is_described_class; + + BOOST_TEST_TRAIT_FALSE((is_described_class)); + BOOST_TEST_TRAIT_FALSE((is_described_class)); + BOOST_TEST_TRAIT_FALSE((is_described_class)); + BOOST_TEST_TRAIT_FALSE((is_described_class)); + BOOST_TEST_TRAIT_FALSE((is_described_class)); + BOOST_TEST_TRAIT_FALSE((is_described_class)); + +#if defined(BOOST_DESCRIBE_CXX14) + + BOOST_TEST_TRAIT_TRUE((is_described_class)); + BOOST_TEST_TRAIT_TRUE((is_described_class)); + +#else + + BOOST_TEST_TRAIT_FALSE((is_described_class)); + BOOST_TEST_TRAIT_FALSE((is_described_class)); + +#endif + + return boost::report_errors(); +} diff --git a/test/is_described_class_test2.cpp b/test/is_described_class_test2.cpp new file mode 100644 index 0000000..70a0d8d --- /dev/null +++ b/test/is_described_class_test2.cpp @@ -0,0 +1,35 @@ +// Copyright 2022 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +struct X +{ +}; + +BOOST_DESCRIBE_STRUCT( X, (), () ) + +namespace boost +{ +namespace container_hash +{ + +template struct is_described_class; +template<> struct is_described_class: boost::false_type {}; + +} // namespace container_hash +} // namespace boost + +#include +#include + +int main() +{ + using boost::container_hash::is_described_class; + + BOOST_TEST_TRAIT_FALSE((is_described_class)); + + return boost::report_errors(); +}