Add is_described_class<T>

This commit is contained in:
Peter Dimov
2022-10-28 01:47:27 +03:00
parent 29c85559e4
commit 0171246a61
4 changed files with 131 additions and 0 deletions

View File

@@ -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 <boost/type_traits/integral_constant.hpp>
#include <boost/describe/bases.hpp>
#include <boost/describe/members.hpp>
namespace boost
{
namespace container_hash
{
#if defined(BOOST_DESCRIBE_CXX11)
template<class T> struct is_described_class: boost::integral_constant<bool,
describe::has_describe_bases<T>::value && describe::has_describe_members<T>::value>
{
};
#else
template<class T> struct is_described_class: boost::false_type
{
};
#endif
} // namespace container_hash
} // namespace boost
#endif // #ifndef BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED

View File

@@ -102,3 +102,8 @@ run is_range_test3.cpp ;
run is_contiguous_range_test2.cpp ; run is_contiguous_range_test2.cpp ;
run is_unordered_range_test2.cpp ; run is_unordered_range_test2.cpp ;
run is_contiguous_range_test3.cpp ; run is_contiguous_range_test3.cpp ;
run is_described_class_test.cpp
: : : <warnings>extra ;
run is_described_class_test2.cpp
: : : <warnings>extra ;

View File

@@ -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 <boost/container_hash/is_described_class.hpp>
#include <boost/describe/class.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <string>
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<void>));
BOOST_TEST_TRAIT_FALSE((is_described_class<int>));
BOOST_TEST_TRAIT_FALSE((is_described_class<X1>));
BOOST_TEST_TRAIT_FALSE((is_described_class<X2>));
BOOST_TEST_TRAIT_FALSE((is_described_class<int[2]>));
BOOST_TEST_TRAIT_FALSE((is_described_class<std::string>));
#if defined(BOOST_DESCRIBE_CXX14)
BOOST_TEST_TRAIT_TRUE((is_described_class<Y1>));
BOOST_TEST_TRAIT_TRUE((is_described_class<Y2>));
#else
BOOST_TEST_TRAIT_FALSE((is_described_class<Y1>));
BOOST_TEST_TRAIT_FALSE((is_described_class<Y2>));
#endif
return boost::report_errors();
}

View File

@@ -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 <boost/type_traits/integral_constant.hpp>
#include <boost/describe/class.hpp>
struct X
{
};
BOOST_DESCRIBE_STRUCT( X, (), () )
namespace boost
{
namespace container_hash
{
template<class T> struct is_described_class;
template<> struct is_described_class<X>: boost::false_type {};
} // namespace container_hash
} // namespace boost
#include <boost/container_hash/is_described_class.hpp>
#include <boost/core/lightweight_test_trait.hpp>
int main()
{
using boost::container_hash::is_described_class;
BOOST_TEST_TRAIT_FALSE((is_described_class<X>));
return boost::report_errors();
}