mirror of
https://github.com/boostorg/container_hash.git
synced 2025-08-03 06:24:41 +02:00
Add is_described_class<T>
This commit is contained in:
35
include/boost/container_hash/is_described_class.hpp
Normal file
35
include/boost/container_hash/is_described_class.hpp
Normal 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
|
@@ -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
|
||||
: : : <warnings>extra ;
|
||||
run is_described_class_test2.cpp
|
||||
: : : <warnings>extra ;
|
||||
|
56
test/is_described_class_test.cpp
Normal file
56
test/is_described_class_test.cpp
Normal 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();
|
||||
}
|
35
test/is_described_class_test2.cpp
Normal file
35
test/is_described_class_test2.cpp
Normal 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();
|
||||
}
|
Reference in New Issue
Block a user