Skip to content
Snippets Groups Projects
Commit 0970580f authored by Jan Trávníček's avatar Jan Trávníček
Browse files

drop inherently wrong is_base_of_any trait

parent 6e8e7547
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -35,28 +35,6 @@ namespace std { ...@@ -35,28 +35,6 @@ namespace std {
static const bool value = sizeof(Yes) == sizeof(has_normalize::test((typename std::remove_reference<T>::type*)0)); static const bool value = sizeof(Yes) == sizeof(has_normalize::test((typename std::remove_reference<T>::type*)0));
}; };
   
// ----------------------------------------------------------------------------------------------------
template <typename T>
struct is_base_of<T, T> {
static const bool value = true;
};
template <typename T, typename... Ts>
struct is_base_of_any;
template <typename T, typename F>
struct is_base_of_any<T, F>
{
static const bool value = is_base_of<T, F>::value;
};
template <typename T, typename F, typename... Ts>
struct is_base_of_any<T, F, Ts...>
{
static const bool value = is_base_of<T, F>::value || is_base_of_any<T, Ts...>::value;
};
// ---------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------
   
template < size_t N, typename ... T > template < size_t N, typename ... T >
......
...@@ -238,7 +238,7 @@ class variant : public variant_base<static_max<SizeOf<Ts>::size...>, static_max< ...@@ -238,7 +238,7 @@ class variant : public variant_base<static_max<SizeOf<Ts>::size...>, static_max<
public: public:
using variant_base<static_max<SizeOf<Ts>::size...>, static_max<AlignOf<Ts>::align...>, Ts...>::variant_base; using variant_base<static_max<SizeOf<Ts>::size...>, static_max<AlignOf<Ts>::align...>, Ts...>::variant_base;
   
template < typename = std::enable_if < std::is_base_of_any<void, Ts...>::value > > template < typename = std::enable_if < std::is_in<void, Ts...>::value > >
variant ( ) : variant_base<static_max<SizeOf<Ts>::size...>, static_max<AlignOf<Ts>::align...>, Ts...> ( ) { variant ( ) : variant_base<static_max<SizeOf<Ts>::size...>, static_max<AlignOf<Ts>::align...>, Ts...> ( ) {
} }
   
...@@ -296,32 +296,32 @@ public: ...@@ -296,32 +296,32 @@ public:
return helper_t::compareHelper(this->type_id, &this->data, other.type_id, &other.data); return helper_t::compareHelper(this->type_id, &this->data, other.type_id, &other.data);
} }
   
template<typename T, typename = std::enable_if < std::is_base_of_any<T, Ts...>::value > > template<typename T, typename = std::enable_if < std::is_in<T, Ts...>::value > >
bool is() const { bool is() const {
return (this->type_id == typeid(T).hash_code()); return (this->type_id == typeid(T).hash_code());
} }
   
template<typename = std::enable_if < std::is_base_of_any<void, Ts...>::value > > template<typename = std::enable_if < std::is_in<void, Ts...>::value > >
void set ( ) { void set ( ) {
helper_t::destroy(this->type_id, &this->data); helper_t::destroy(this->type_id, &this->data);
this->type_id = typeid(void).hash_code(); this->type_id = typeid(void).hash_code();
} }
   
template<typename T, typename = std::enable_if < std::is_base_of_any<T, Ts...>::value && ! std::is_same < void, T >::value > > template<typename T, typename = std::enable_if < std::is_in<T, Ts...>::value && ! std::is_same < void, T >::value > >
void set(T&& value) { void set(T&& value) {
helper_t::destroy(this->type_id, &this->data); helper_t::destroy(this->type_id, &this->data);
new (&this->data) T(value); new (&this->data) T(value);
this->type_id = typeid(T).hash_code(); this->type_id = typeid(T).hash_code();
} }
   
template<typename T, typename = std::enable_if < std::is_base_of_any<T, Ts...>::value && ! std::is_same < void, T >::value > > template<typename T, typename = std::enable_if < std::is_in<T, Ts...>::value && ! std::is_same < void, T >::value > >
void set(const T& value) { void set(const T& value) {
helper_t::destroy(this->type_id, &this->data); helper_t::destroy(this->type_id, &this->data);
new (&this->data) T(std::move(value)); new (&this->data) T(std::move(value));
this->type_id = typeid(T).hash_code(); this->type_id = typeid(T).hash_code();
} }
   
template<typename T, typename = std::enable_if < std::is_base_of_any<T, Ts...>::value && ! std::is_same < void, T >::value > > template<typename T, typename = std::enable_if < std::is_in<T, Ts...>::value && ! std::is_same < void, T >::value > >
T& get() { T& get() {
// It is a dynamic_cast-like behaviour // It is a dynamic_cast-like behaviour
if (this->type_id == typeid(T).hash_code()) if (this->type_id == typeid(T).hash_code())
...@@ -330,7 +330,7 @@ public: ...@@ -330,7 +330,7 @@ public:
throw std::bad_cast(); throw std::bad_cast();
} }
   
template<typename T, typename = std::enable_if < std::is_base_of_any<T, Ts...>::value && ! std::is_same < void, T >::value > > template<typename T, typename = std::enable_if < std::is_in<T, Ts...>::value && ! std::is_same < void, T >::value > >
const T& get() const { const T& get() const {
// It is a dynamic_cast-like behaviour // It is a dynamic_cast-like behaviour
if (this->type_id == typeid(T).hash_code()) if (this->type_id == typeid(T).hash_code())
......
...@@ -10,13 +10,6 @@ void TypeTraitsTest::setUp() { ...@@ -10,13 +10,6 @@ void TypeTraitsTest::setUp() {
void TypeTraitsTest::tearDown() { void TypeTraitsTest::tearDown() {
} }
   
void TypeTraitsTest::testIsBaseOf() {
CPPUNIT_ASSERT( ( std::is_base_of_any<int, int, std::string, TypeTraitsTest::test>::value ) == true );
CPPUNIT_ASSERT( ( std::is_base_of<int, int>::value ) == true );
CPPUNIT_ASSERT( ( std::is_base_of<int, std::string>::value ) == false );
CPPUNIT_ASSERT( ( std::is_base_of<int, TypeTraitsTest::test>::value ) == false );
}
void TypeTraitsTest::testAccessPackElement() { void TypeTraitsTest::testAccessPackElement() {
CPPUNIT_ASSERT( ( std::is_same< std::get_type_pack_element < 0, int, double >::type, int >::value ) == true ); CPPUNIT_ASSERT( ( std::is_same< std::get_type_pack_element < 0, int, double >::type, int >::value ) == true );
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
class TypeTraitsTest : public CppUnit::TestFixture class TypeTraitsTest : public CppUnit::TestFixture
{ {
CPPUNIT_TEST_SUITE( TypeTraitsTest ); CPPUNIT_TEST_SUITE( TypeTraitsTest );
CPPUNIT_TEST( testIsBaseOf );
CPPUNIT_TEST( testAccessPackElement ); CPPUNIT_TEST( testAccessPackElement );
CPPUNIT_TEST( testTypeInPack ); CPPUNIT_TEST( testTypeInPack );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -64,7 +63,6 @@ public: ...@@ -64,7 +63,6 @@ public:
void setUp(); void setUp();
void tearDown(); void tearDown();
   
void testIsBaseOf();
void testAccessPackElement(); void testAccessPackElement();
void testTypeInPack(); void testTypeInPack();
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment