Merge pull request #49 from boostorg/final

Avoid inheritance for final types in compressed_pair
This commit is contained in:
Glen Fernandes 2018-09-12 22:29:26 -04:00 committed by GitHub
commit 3d2a7f0c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 8 deletions

View File

@ -24,6 +24,7 @@
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/is_empty.hpp>
#include <boost/type_traits/is_final.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/call_traits.hpp>
@ -42,6 +43,14 @@ class compressed_pair;
namespace details
{
template<class T, bool E = boost::is_final<T>::value>
struct compressed_pair_empty
: ::boost::false_type { };
template<class T>
struct compressed_pair_empty<T, false>
: ::boost::is_empty<T> { };
// JM altered 26 Jan 2000:
template <class T1, class T2, bool IsSame, bool FirstEmpty, bool SecondEmpty>
struct compressed_pair_switch;
@ -343,8 +352,8 @@ class compressed_pair
T1,
T2,
::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
::boost::is_empty<T1>::value,
::boost::is_empty<T2>::value>::value>
::boost::details::compressed_pair_empty<T1>::value,
::boost::details::compressed_pair_empty<T2>::value>::value>
{
private:
typedef details::compressed_pair_imp<T1, T2,
@ -352,8 +361,8 @@ private:
T1,
T2,
::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
::boost::is_empty<T1>::value,
::boost::is_empty<T2>::value>::value> base;
::boost::details::compressed_pair_empty<T1>::value,
::boost::details::compressed_pair_empty<T2>::value>::value> base;
public:
typedef T1 first_type;
typedef T2 second_type;
@ -388,8 +397,8 @@ class compressed_pair<T, T>
T,
T,
::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
::boost::is_empty<T>::value,
::boost::is_empty<T>::value>::value>
::boost::details::compressed_pair_empty<T>::value,
::boost::details::compressed_pair_empty<T>::value>::value>
{
private:
typedef details::compressed_pair_imp<T, T,
@ -397,8 +406,8 @@ private:
T,
T,
::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
::boost::is_empty<T>::value,
::boost::is_empty<T>::value>::value> base;
::boost::details::compressed_pair_empty<T>::value,
::boost::details::compressed_pair_empty<T>::value>::value> base;
public:
typedef T first_type;
typedef T second_type;

View File

@ -16,6 +16,7 @@ run binary_test.cpp ;
run call_traits_test.cpp : -u ;
run compressed_pair_test.cpp ;
run compressed_pair_final_test.cpp ;
run iterators_test.cpp ;

View File

@ -0,0 +1,55 @@
/*
Copyright 2018 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_FINAL)
#include <boost/compressed_pair.hpp>
#include <boost/core/lightweight_test.hpp>
struct type1 {
operator bool() const {
return false;
}
};
struct type2 final {
operator bool() const {
return false;
}
};
#if !defined(BOOST_IS_FINAL)
namespace boost {
template<>
struct is_final<type2>
: true_type { };
} /* boost*/
#endif
template<class T1, class T2>
void test()
{
boost::compressed_pair<T1, T2> p;
BOOST_TEST(!p.first());
BOOST_TEST(!p.second());
}
int main()
{
test<type1, type2>();
test<type2, type1>();
test<type2, type2>();
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif