Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ecatmur committed Apr 12, 2020
1 parent 4b77c5a commit ad1dd5a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 57 deletions.
3 changes: 0 additions & 3 deletions include/boost/test/data/monomorphic/singleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

#include <boost/test/detail/suppress_warnings.hpp>

// Boost
#include <boost/type_traits/decay.hpp>

//____________________________________________________________________________//

namespace boost {
Expand Down
4 changes: 2 additions & 2 deletions include/boost/test/tools/collection_comparison_op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ compare_collections( Lhs const& lhs, Rhs const& rhs, boost::type<op::GE<L, R> >*
template<typename Lhs,typename Rhs> \
struct name<Lhs,Rhs,typename boost::enable_if_c< \
unit_test::is_forward_iterable<Lhs>::value \
&& !unit_test::is_cstring_comparable<Lhs>::value \
&& unit_test::is_forward_iterable<Rhs>::value \
&& !( unit_test::is_cstring_comparable<Lhs>::value \
|| unit_test::is_cstring_comparable<Rhs>::value)>::type> { \
&& !unit_test::is_cstring_comparable<Rhs>::value>::type> { \
public: \
typedef assertion_result result_type; \
typedef name_inverse<Lhs, Rhs> inverse; \
Expand Down
20 changes: 0 additions & 20 deletions include/boost/test/utils/basic_cstring/basic_cstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,6 @@ class BOOST_SYMBOL_VISIBLE basic_cstring {
static CharT null;
};

// ************************************************************************** //
// ************** cstring_forward_iterable_helper ************** //
// ************************************************************************** //


// Helper for instantiating a subclass of cstring using a forward iterable.
//! @internal
template <class CharT, class forward_iterable>
class BOOST_SYMBOL_VISIBLE cstring_forward_iterable_helper : public basic_cstring<CharT const> {
public:
cstring_forward_iterable_helper(forward_iterable const& fi)
: m_storage(fi.begin(), fi.end())
{
this->assign(m_storage.c_str(), m_storage.size());
}
private:
std::basic_string<CharT> m_storage;
};


// ************************************************************************** //
// ************** cstring_string_view_helper ************** //
// ************************************************************************** //
Expand Down
41 changes: 20 additions & 21 deletions include/boost/test/utils/is_cstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP
#define BOOST_TEST_UTILS_IS_CSTRING_HPP

// Boost.Test
#include <boost/test/utils/is_forward_iterable.hpp>

// Boost
#include <boost/mpl/bool.hpp>
#include <boost/type_traits/is_same.hpp>
Expand Down Expand Up @@ -56,13 +53,17 @@ struct is_cstring_impl<char*> : public mpl::true_ {};
template<>
struct is_cstring_impl<wchar_t*> : public mpl::true_ {};

template <typename T,
bool is_cstring = is_cstring_impl<T>::value,
bool is_forward_iterable_ = is_forward_iterable<T>::value>
template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value >
struct deduce_cstring_transform_impl;

template <typename T, bool is_cstring >
struct deduce_cstring_transform_impl<T&, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};

template <typename T, bool is_cstring >
struct deduce_cstring_transform_impl<T const, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};

template <typename T>
struct deduce_cstring_transform_impl<T, true, false> {
struct deduce_cstring_transform_impl<T, true> {
typedef typename boost::add_const<
typename boost::remove_pointer<
typename boost::decay<T>::type
Expand All @@ -72,27 +73,21 @@ struct deduce_cstring_transform_impl<T, true, false> {
};

template <typename T>
struct deduce_cstring_transform_impl<T, false, true> {
typedef typename boost::remove_const<typename bt_iterator_traits<T>::value_type>::type U;
typedef typename boost::conditional<
boost::is_same<U, char>::value || boost::is_same<U, wchar_t>::value,
cstring_forward_iterable_helper<U, T>,
T>::type type;
};

template <typename T>
struct deduce_cstring_transform_impl< T, false, false > {
typedef T type;
struct deduce_cstring_transform_impl< T, false > {
typedef typename
boost::remove_const<
typename boost::remove_reference<T>::type
>::type type;
};

template <typename T>
struct deduce_cstring_transform_impl< std::basic_string<T, std::char_traits<T> >, false, true > {
struct deduce_cstring_transform_impl< std::basic_string<T, std::char_traits<T> >, false > {
typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type;
};

#if defined(BOOST_TEST_STRING_VIEW)
template <typename T>
struct deduce_cstring_transform_impl< std::basic_string_view<T, std::char_traits<T> >, false, true > {
struct deduce_cstring_transform_impl< std::basic_string_view<T, std::char_traits<T> >, false > {
private:
using sv_t = std::basic_string_view<T, std::char_traits<T> > ;

Expand Down Expand Up @@ -125,7 +120,11 @@ struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : publ

template <class T>
struct deduce_cstring_transform {
typedef typename ut_detail::deduce_cstring_transform_impl<typename boost::decay<T>::type>::type type;
typedef typename
boost::remove_const<
typename boost::remove_reference<T>::type
>::type U;
typedef typename ut_detail::deduce_cstring_transform_impl<typename boost::decay<U>::type>::type type;
};

} // namespace unit_test
Expand Down
6 changes: 3 additions & 3 deletions include/boost/test/utils/is_forward_iterable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#endif
#endif

#if defined(BOOST_TEST_FWD_ITERABLE_CXX03)
// Boost
#include <boost/mpl/bool.hpp>

#if defined(BOOST_TEST_FWD_ITERABLE_CXX03)
// STL
#include <list>
#include <vector>
Expand All @@ -37,10 +37,10 @@
// Boost
#include <boost/static_assert.hpp>
#include <boost/utility/declval.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/add_pointer.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/test/utils/is_cstring.hpp>

// STL
#include <utility>
Expand Down
11 changes: 3 additions & 8 deletions test/writing-test-ts/collection-comparison-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,12 @@ BOOST_AUTO_TEST_CASE( test_collection_of_collection_comp )

//____________________________________________________________________________//

BOOST_AUTO_TEST_CASE( test_string_non_string )
BOOST_AUTO_TEST_CASE( test_string_non_string_per_element )
{
std::string a("abc");
std::vector<char> b{'a', 'b', 'c'};
std::vector<int> c{'a', 'b', 'c'};
char const* a = "abc";
std::vector<int> b{'a', 'b', 'c'};
BOOST_TEST( a == b, tt::per_element() );
BOOST_TEST( b == a, tt::per_element() );
BOOST_TEST( a == c, tt::per_element() );
BOOST_TEST( c == a, tt::per_element() );
BOOST_TEST( b == c, tt::per_element() );
BOOST_TEST( c == b, tt::per_element() );
}

//____________________________________________________________________________//
Expand Down

0 comments on commit ad1dd5a

Please sign in to comment.