Merge branch 'patch-1' of https://github.com/igaztanaga/tuple into feature/pr-21

This commit is contained in:
Peter Dimov
2021-11-16 19:37:28 +02:00

View File

@ -34,6 +34,7 @@
#include <utility> // needed for the assignment from pair to tuple #include <utility> // needed for the assignment from pair to tuple
#include <cstddef> // for std::size_t
#include <boost/type_traits/cv_traits.hpp> #include <boost/type_traits/cv_traits.hpp>
#include <boost/type_traits/function_traits.hpp> #include <boost/type_traits/function_traits.hpp>
@ -93,7 +94,7 @@ namespace detail {
template<class T> template<class T>
class generate_error; class generate_error;
template<int N> template<std::size_t N>
struct drop_front { struct drop_front {
template<class Tuple> template<class Tuple>
struct apply { struct apply {
@ -127,14 +128,14 @@ struct drop_front<0> {
#ifndef BOOST_NO_CV_SPECIALIZATIONS #ifndef BOOST_NO_CV_SPECIALIZATIONS
template<int N, class T> template<std::size_t N, class T>
struct element struct element
{ {
typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
apply<T>::type::head_type type; apply<T>::type::head_type type;
}; };
template<int N, class T> template<std::size_t N, class T>
struct element<N, const T> struct element<N, const T>
{ {
private: private:
@ -151,14 +152,14 @@ public:
namespace detail { namespace detail {
template<int N, class T, bool IsConst> template<std::size_t N, class T, bool IsConst>
struct element_impl struct element_impl
{ {
typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
apply<T>::type::head_type type; apply<T>::type::head_type type;
}; };
template<int N, class T> template<std::size_t N, class T>
struct element_impl<N, T, true /* IsConst */> struct element_impl<N, T, true /* IsConst */>
{ {
typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
@ -169,7 +170,7 @@ struct element_impl<N, T, true /* IsConst */>
} // end of namespace detail } // end of namespace detail
template<int N, class T> template<std::size_t N, class T>
struct element: struct element:
public detail::element_impl<N, T, ::boost::is_const<T>::value> public detail::element_impl<N, T, ::boost::is_const<T>::value>
{ {
@ -210,7 +211,7 @@ template <class T> struct access_traits<T&> {
// get function for non-const cons-lists, returns a reference to the element // get function for non-const cons-lists, returns a reference to the element
template<int N, class HT, class TT> template<std::size_t N, class HT, class TT>
inline typename access_traits< inline typename access_traits<
typename element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::non_const_type >::non_const_type
@ -224,7 +225,7 @@ get(cons<HT, TT>& c) {
// get function for const cons-lists, returns a const reference to // get function for const cons-lists, returns a const reference to
// the element. If the element is a reference, returns the reference // the element. If the element is a reference, returns the reference
// as such (that is, can return a non-const reference) // as such (that is, can return a non-const reference)
template<int N, class HT, class TT> template<std::size_t N, class HT, class TT>
inline typename access_traits< inline typename access_traits<
typename element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::const_type >::const_type
@ -333,7 +334,7 @@ struct cons {
} }
// get member functions (non-const and const) // get member functions (non-const and const)
template <int N> template <std::size_t N>
typename access_traits< typename access_traits<
typename element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::non_const_type >::non_const_type
@ -341,7 +342,7 @@ struct cons {
return boost::tuples::get<N>(*this); // delegate to non-member get return boost::tuples::get<N>(*this); // delegate to non-member get
} }
template <int N> template <std::size_t N>
typename access_traits< typename access_traits<
typename element<N, cons<HT, TT> >::type typename element<N, cons<HT, TT> >::type
>::const_type >::const_type
@ -403,7 +404,7 @@ struct cons<HT, null_type> {
// is illformed if HT is a reference // is illformed if HT is a reference
cons& operator=(const cons& u) { head = u.head; return *this; } cons& operator=(const cons& u) { head = u.head; return *this; }
template <int N> template <std::size_t N>
typename access_traits< typename access_traits<
typename element<N, self_type>::type typename element<N, self_type>::type
>::non_const_type >::non_const_type
@ -411,7 +412,7 @@ struct cons<HT, null_type> {
return boost::tuples::get<N>(*this); return boost::tuples::get<N>(*this);
} }
template <int N> template <std::size_t N>
typename access_traits< typename access_traits<
typename element<N, self_type>::type typename element<N, self_type>::type
>::const_type >::const_type
@ -424,27 +425,27 @@ struct cons<HT, null_type> {
// templates for finding out the length of the tuple ------------------- // templates for finding out the length of the tuple -------------------
template<class T> template<class T>
struct length: boost::integral_constant<int, 1 + length<typename T::tail_type>::value> struct length: boost::integral_constant<std::size_t, 1 + length<typename T::tail_type>::value>
{ {
}; };
template<> template<>
struct length<tuple<> >: boost::integral_constant<int, 0> struct length<tuple<> >: boost::integral_constant<std::size_t, 0>
{ {
}; };
template<> template<>
struct length<tuple<> const>: boost::integral_constant<int, 0> struct length<tuple<> const>: boost::integral_constant<std::size_t, 0>
{ {
}; };
template<> template<>
struct length<null_type>: boost::integral_constant<int, 0> struct length<null_type>: boost::integral_constant<std::size_t, 0>
{ {
}; };
template<> template<>
struct length<null_type const>: boost::integral_constant<int, 0> struct length<null_type const>: boost::integral_constant<std::size_t, 0>
{ {
}; };
@ -676,20 +677,20 @@ struct make_tuple_traits<T&> {
// All arrays are converted to const. This is because make_tuple takes its // All arrays are converted to const. This is because make_tuple takes its
// parameters as const T& and thus the knowledge of the potential // parameters as const T& and thus the knowledge of the potential
// non-constness of actual argument is lost. // non-constness of actual argument is lost.
template<class T, int n> struct make_tuple_traits <T[n]> { template<class T, std::size_t n> struct make_tuple_traits <T[n]> {
typedef const T (&type)[n]; typedef const T (&type)[n];
}; };
template<class T, int n> template<class T, std::size_t n>
struct make_tuple_traits<const T[n]> { struct make_tuple_traits<const T[n]> {
typedef const T (&type)[n]; typedef const T (&type)[n];
}; };
template<class T, int n> struct make_tuple_traits<volatile T[n]> { template<class T, std::size_t n> struct make_tuple_traits<volatile T[n]> {
typedef const volatile T (&type)[n]; typedef const volatile T (&type)[n];
}; };
template<class T, int n> template<class T, std::size_t n>
struct make_tuple_traits<const volatile T[n]> { struct make_tuple_traits<const volatile T[n]> {
typedef const volatile T (&type)[n]; typedef const volatile T (&type)[n];
}; };