Skip to content

Commit

Permalink
Remove uses of Boost.TypeTraits
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Dec 1, 2023
1 parent 05749a3 commit 34ae31a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 337 deletions.
14 changes: 6 additions & 8 deletions include/boost/hash2/get_integral_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

// Copyright 2017, 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/hash2/byte_type.hpp>
#include <boost/hash2/detail/read.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/array.hpp>
#include <boost/static_assert.hpp>
#include <type_traits>
#include <cstddef>

namespace boost
Expand All @@ -20,18 +18,18 @@ namespace hash2
{

template<class T, class R>
typename boost::enable_if_c<boost::is_integral<R>::value && (sizeof(R) >= sizeof(T)), T>::type
typename std::enable_if<std::is_integral<R>::value && (sizeof(R) >= sizeof(T)), T>::type
get_integral_result( R const & r )
{
typedef typename boost::make_unsigned<T>::type U;
typedef typename std::make_unsigned<T>::type U;
return static_cast<T>( static_cast<U>( r ) );
}

template<class T, class R>
typename boost::enable_if_c<boost::is_integral<R>::value && sizeof(R) == 4 && sizeof(T) == 8, T>::type
typename std::enable_if<std::is_integral<R>::value && sizeof(R) == 4 && sizeof(T) == 8, T>::type
get_integral_result( R const & r )
{
typedef typename boost::make_unsigned<T>::type U;
typedef typename std::make_unsigned<T>::type U;
return static_cast<T>( ( static_cast<U>( r ) << 32 ) + r );
}

Expand Down
63 changes: 10 additions & 53 deletions include/boost/hash2/hash_append.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// Copyright 2017, 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
//
// Based on
//
Expand All @@ -17,14 +18,13 @@
#include <boost/hash2/is_tuple_like.hpp>
#include <boost/hash2/byte_type.hpp>
#include <boost/hash2/get_integral_result.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
# include <boost/mp11/integer_sequence.hpp>
#endif
#include <type_traits>
#include <iterator>

namespace boost
Expand Down Expand Up @@ -63,7 +63,7 @@ template<class H> void hash_append_range_( H & h, byte_type const * first, byte_
}

template<class H, class T>
typename boost::enable_if_c<
typename std::enable_if<
is_contiguously_hashable<T, H>::value, void >::type
hash_append_range_( H & h, T * first, T * last )
{
Expand Down Expand Up @@ -122,7 +122,7 @@ template<class H, class It> void hash_append_sized_range( H & h, It first, It la
// contiguously hashable (this includes byte_type const&)

template<class H, class T>
typename boost::enable_if_c<
typename std::enable_if<
is_contiguously_hashable<T, H>::value, void >::type
do_hash_append( H & h, T const & v )
{
Expand All @@ -133,7 +133,7 @@ template<class H, class T>
// floating point

template<class H, class T>
typename boost::enable_if_c< is_floating_point<T>::value, void >::type
typename std::enable_if< std::is_floating_point<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
T w = v == 0? 0: v;
Expand All @@ -151,61 +151,18 @@ template<class H, class T, std::size_t N> void do_hash_append( H & h, T const (&

// contiguous containers and ranges, w/ size

#if BOOST_WORKAROUND(BOOST_MSVC, <= 1500)

// std::vector has no data()

namespace detail
{

template<class T> struct is_vector: false_type
{
};

template<class T, class A> struct is_vector< std::vector<T, A> >: true_type
{
};

template<class T, class A> struct is_vector< std::vector<T, A> const >: true_type
{
};

} // namespace detail

template<class H, class T>
typename boost::enable_if_c< is_contiguous_range<T>::value && !is_tuple_like<T>::value && !detail::is_vector<T>::value, void >::type
typename std::enable_if< is_contiguous_range<T>::value && !is_tuple_like<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
hash_append_range( h, v.data(), v.data() + v.size() );
hash_append_size( h, v.size() );
}

template<class H, class T>
typename boost::enable_if_c< detail::is_vector<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
typename T::value_type const * p = v.empty()? 0: &v[0];

hash_append_range( h, p, p + v.size() );
hash_append_size( h, v.size() );
}

#else

template<class H, class T>
typename boost::enable_if_c< is_contiguous_range<T>::value && !is_tuple_like<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
hash_append_range( h, v.data(), v.data() + v.size() );
hash_append_size( h, v.size() );
}

#endif

// containers and ranges, w/ size

template<class H, class T>
typename boost::enable_if_c< is_range<T>::value && !is_tuple_like<T>::value && !is_contiguous_range<T>::value && !is_unordered_range<T>::value, void >::type
typename std::enable_if< is_range<T>::value && !is_tuple_like<T>::value && !is_contiguous_range<T>::value && !is_unordered_range<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
hash_append_sized_range( h, v.begin(), v.end() );
Expand All @@ -214,7 +171,7 @@ template<class H, class T>
// std::array (both range and tuple-like)

template<class H, class T>
typename boost::enable_if_c< is_range<T>::value && is_tuple_like<T>::value, void >::type
typename std::enable_if< is_range<T>::value && is_tuple_like<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
hash_append_range( h, v.begin(), v.end() );
Expand Down Expand Up @@ -247,7 +204,7 @@ template<class H, class It> void hash_append_unordered_range_( H & h, It first,
} // namespace detail

template<class H, class T>
typename boost::enable_if_c< is_unordered_range<T>::value, void >::type
typename std::enable_if< is_unordered_range<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
detail::hash_append_unordered_range_( h, v.begin(), v.end() );
Expand All @@ -274,7 +231,7 @@ template<class H, class T> void hash_append_tuple( H & /*h*/, T const& /*v*/, bo
} // namespace detail

template<class H, class T>
typename boost::enable_if_c< !is_range<T>::value && is_tuple_like<T>::value, void >::type
typename std::enable_if< !is_range<T>::value && is_tuple_like<T>::value, void >::type
do_hash_append( H & h, T const & v )
{
typedef boost::mp11::make_index_sequence<std::tuple_size<T>::value> seq;
Expand Down
82 changes: 7 additions & 75 deletions include/boost/hash2/is_contiguous_range.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@

// Copyright 2017, 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.

#ifndef BOOST_HASH2_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
#define BOOST_HASH2_IS_CONTIGUOUS_RANGE_HPP_INCLUDED

#include <boost/type_traits/integral_constant.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>

#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)
// Copyright 2017, 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/declval.hpp>
#include <boost/type_traits/is_same.hpp>
#include <type_traits>
#include <iterator>

namespace boost
Expand All @@ -25,11 +17,11 @@ namespace detail
{

template<class It, class T, class S>
integral_constant< bool, is_same<typename std::iterator_traits<It>::value_type, T>::value && is_integral<S>::value >
std::integral_constant< bool, std::is_same<typename std::iterator_traits<It>::value_type, T>::value && std::is_integral<S>::value >
is_contiguous_range_check( It first, It last, T const*, T const*, S );

template<class T> decltype( is_contiguous_range_check( declval<T&>().begin(), declval<T&>().end(), declval<T&>().data(), declval<T&>().data() + declval<T&>().size(), declval<T&>().size() ) ) is_contiguous_range_( int );
template<class T> false_type is_contiguous_range_( ... );
template<class T> decltype( is_contiguous_range_check( std::declval<T&>().begin(), std::declval<T&>().end(), std::declval<T&>().data(), std::declval<T&>().data() + std::declval<T&>().size(), std::declval<T&>().size() ) ) is_contiguous_range_( int );
template<class T> std::false_type is_contiguous_range_( ... );

} // namespace detail

Expand All @@ -40,64 +32,4 @@ template<class T> struct is_contiguous_range: decltype( detail::is_contiguous_ra
} // namespace hash2
} // namespace boost

#else // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)

#include <boost/array.hpp>
#include <cstddef>
#include <vector>
#include <string>
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
#include <array>
#endif

namespace boost
{
namespace hash2
{

template<class T> struct is_contiguous_range: false_type
{
};

template<class T, std::size_t N> struct is_contiguous_range< boost::array<T, N> >: true_type
{
};

template<class T, std::size_t N> struct is_contiguous_range< boost::array<T, N> const >: true_type
{
};

template<class T, class A> struct is_contiguous_range< std::vector<T, A> >: true_type
{
};

template<class T, class A> struct is_contiguous_range< std::vector<T, A> const >: true_type
{
};

template<class E, class T, class A> struct is_contiguous_range< std::basic_string<E, T, A> >: true_type
{
};

template<class E, class T, class A> struct is_contiguous_range< std::basic_string<E, T, A> const >: true_type
{
};

#if !defined(BOOST_NO_CXX11_HDR_ARRAY)

template<class T, std::size_t N> struct is_contiguous_range< std::array<T, N> >: true_type
{
};

template<class T, std::size_t N> struct is_contiguous_range< std::array<T, N> const >: true_type
{
};

#endif

} // namespace hash2
} // namespace boost

#endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)

#endif // #ifndef BOOST_HASH2_IS_CONTIGUOUS_RANGE_HPP_INCLUDED
47 changes: 7 additions & 40 deletions include/boost/hash2/is_range.hpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,32 @@
#ifndef BOOST_HASH2_IS_RANGE_HPP_INCLUDED
#define BOOST_HASH2_IS_RANGE_HPP_INCLUDED

// Copyright 2017 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_HASH2_IS_RANGE_HPP_INCLUDED
#define BOOST_HASH2_IS_RANGE_HPP_INCLUDED

#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/declval.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <type_traits>
#include <iterator>

namespace boost
{
namespace hash2
{

#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700)

namespace detail
{

template<class It> true_type is_range_check( It first, It last, typename std::iterator_traits<It>::difference_type* = 0 );
template<class It> std::true_type is_range_check( It first, It last, typename std::iterator_traits<It>::difference_type* = 0 );

template<class T> decltype( is_range_check( declval<T&>().begin(), declval<T&>().end() ) ) is_range_( int );
template<class T> false_type is_range_( ... );
template<class T> decltype( is_range_check( std::declval<T&>().begin(), std::declval<T&>().end() ) ) is_range_( int );
template<class T> std::false_type is_range_( ... );

} // namespace detail

template<class T> struct is_range: decltype( detail::is_range_<T>( 0 ) )
{
};

#else

namespace detail
{

template<class T, class E = true_type> struct is_range_: false_type
{
};

template<class T> struct is_range_< T, integral_constant< bool,
is_same<typename T::value_type, typename std::iterator_traits<typename T::iterator>::value_type>::value &&
is_same<typename T::value_type, typename std::iterator_traits<typename T::const_iterator>::value_type>::value &&
is_integral<typename T::size_type>::value
> >: true_type
{
};

} // namespace detail

template<class T> struct is_range: detail::is_range_<T>
{
};

#endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR)

} // namespace hash2
} // namespace boost

Expand Down
Loading

0 comments on commit 34ae31a

Please sign in to comment.