Commit 97d57665 by François Dumont

stl_algo.h (merge): Fix documentation.

2019-09-28  François Dumont  <fdumont@gcc.gnu.org>

	* include/bits/stl_algo.h (merge): Fix documentation.
	* include/debug/functions.h (__check_sorted_aux): Add C++20 constexpr.
	(__check_sorted): Likewise and remove nested irreflexive check.
	(__check_sorted_set_aux, __check_sorted_set): Add C++20 constexpr.
	(__check_partitioned_lower, __check_partitioned_upper): Likewise.
	(_Irreflexive_checker::_S_is_valid): Likewise.
	(__is_irreflexive, __is_irreflexive_pred): Likewise.
	* include/debug/helper_functions.h (__get_distance): Add constexpr.
	(__valid_range_aux): Add C++20 constexpr.
	(__valid_range(_Iter, _Iter, _Distance_traits<_Iter>::__type&)):
	Likewise and add std::is_constant_evaluated check.
	(__valid_range_aux(_Iter, _Iter, std::input_iterator_tag)): New.
	(__valid_range_aux(_Iter, _Iter, std::random_accss_iterator_tag)): New.
	(__valid_range_aux(_Integral, _Integral, std::__true_type)): New,
	use latter.
	(__valid_range(_Iter, _Iter)): Adapt to use latter, add constexpr and
	__builtin_is_contant_evaludated check..
	(__can_advance, __base): Add constexpr.
	* include/debug/macros.h [_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED]
	(_GLIBCXX_DEBUG_VERIFY_COND_AT): New.
	(__glibcxx_check_sorted): Use __glibcxx_check_irreflexive.
	(__glibcxx_check_sorted_pred): Use __glibcxx_check_irreflexive_pred.
	* testsuite/25_algorithms/binary_search/constexpr.cc: Use irreflexive
	std::less.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: Likewise.
	* testsuite/25_algorithms/merge/constexpr.cc: Fix order in camm. Fix
	lambda to be irreflexive.

From-SVN: r276260
parent 23cb6f8e
2019-09-28 François Dumont <fdumont@gcc.gnu.org>
* include/bits/stl_algo.h (merge): Fix documentation.
* include/debug/functions.h (__check_sorted_aux): Add C++20 constexpr.
(__check_sorted): Likewise and remove nested irreflexive check.
(__check_sorted_set_aux, __check_sorted_set): Add C++20 constexpr.
(__check_partitioned_lower, __check_partitioned_upper): Likewise.
(_Irreflexive_checker::_S_is_valid): Likewise.
(__is_irreflexive, __is_irreflexive_pred): Likewise.
* include/debug/helper_functions.h (__get_distance): Add constexpr.
(__valid_range_aux): Add C++20 constexpr.
(__valid_range(_Iter, _Iter, _Distance_traits<_Iter>::__type&)):
Likewise and add std::is_constant_evaluated check.
(__valid_range_aux(_Iter, _Iter, std::input_iterator_tag)): New.
(__valid_range_aux(_Iter, _Iter, std::random_accss_iterator_tag)): New.
(__valid_range_aux(_Integral, _Integral, std::__true_type)): New,
use latter.
(__valid_range(_Iter, _Iter)): Adapt to use latter, add constexpr and
__builtin_is_contant_evaludated check..
(__can_advance, __base): Add constexpr.
* include/debug/macros.h [_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED]
(_GLIBCXX_DEBUG_VERIFY_COND_AT): New.
(__glibcxx_check_sorted): Use __glibcxx_check_irreflexive.
(__glibcxx_check_sorted_pred): Use __glibcxx_check_irreflexive_pred.
* testsuite/25_algorithms/binary_search/constexpr.cc: Use irreflexive
std::less.
* testsuite/25_algorithms/is_sorted/constexpr.cc: Likewise.
* testsuite/25_algorithms/merge/constexpr.cc: Fix order in camm. Fix
lambda to be irreflexive.
2019-09-27 Maciej W. Rozycki <macro@wdc.com> 2019-09-27 Maciej W. Rozycki <macro@wdc.com>
* configure: Regenerate. * configure: Regenerate.
......
...@@ -5057,8 +5057,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO ...@@ -5057,8 +5057,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
* @param __last1 Another iterator. * @param __last1 Another iterator.
* @param __last2 Another iterator. * @param __last2 Another iterator.
* @param __result An iterator pointing to the end of the merged range. * @param __result An iterator pointing to the end of the merged range.
* @return An iterator pointing to the first element <em>not less * @return An output iterator equal to @p __result + (__last1 - __first1)
* than</em> @e val. * + (__last2 - __first2).
* *
* Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into * Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
* the sorted range @p [__result, __result + (__last1-__first1) + * the sorted range @p [__result, __result + (__last1-__first1) +
...@@ -5105,8 +5105,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO ...@@ -5105,8 +5105,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
* @param __last2 Another iterator. * @param __last2 Another iterator.
* @param __result An iterator pointing to the end of the merged range. * @param __result An iterator pointing to the end of the merged range.
* @param __comp A functor to use for comparisons. * @param __comp A functor to use for comparisons.
* @return An iterator pointing to the first element "not less * @return An output iterator equal to @p __result + (__last1 - __first1)
* than" @e val. * + (__last2 - __first2).
* *
* Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into * Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
* the sorted range @p [__result, __result + (__last1-__first1) + * the sorted range @p [__result, __result + (__last1-__first1) +
......
...@@ -219,6 +219,7 @@ namespace __gnu_debug ...@@ -219,6 +219,7 @@ namespace __gnu_debug
// Can't check if an input iterator sequence is sorted, because we // Can't check if an input iterator sequence is sorted, because we
// can't step through the sequence. // can't step through the sequence.
template<typename _InputIterator> template<typename _InputIterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_aux(const _InputIterator&, const _InputIterator&, __check_sorted_aux(const _InputIterator&, const _InputIterator&,
std::input_iterator_tag) std::input_iterator_tag)
...@@ -227,6 +228,7 @@ namespace __gnu_debug ...@@ -227,6 +228,7 @@ namespace __gnu_debug
// Can verify if a forward iterator sequence is in fact sorted using // Can verify if a forward iterator sequence is in fact sorted using
// std::__is_sorted // std::__is_sorted
template<typename _ForwardIterator> template<typename _ForwardIterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last, __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
std::forward_iterator_tag) std::forward_iterator_tag)
...@@ -245,6 +247,7 @@ namespace __gnu_debug ...@@ -245,6 +247,7 @@ namespace __gnu_debug
// Can't check if an input iterator sequence is sorted, because we can't step // Can't check if an input iterator sequence is sorted, because we can't step
// through the sequence. // through the sequence.
template<typename _InputIterator, typename _Predicate> template<typename _InputIterator, typename _Predicate>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_aux(const _InputIterator&, const _InputIterator&, __check_sorted_aux(const _InputIterator&, const _InputIterator&,
_Predicate, std::input_iterator_tag) _Predicate, std::input_iterator_tag)
...@@ -253,6 +256,7 @@ namespace __gnu_debug ...@@ -253,6 +256,7 @@ namespace __gnu_debug
// Can verify if a forward iterator sequence is in fact sorted using // Can verify if a forward iterator sequence is in fact sorted using
// std::__is_sorted // std::__is_sorted
template<typename _ForwardIterator, typename _Predicate> template<typename _ForwardIterator, typename _Predicate>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last, __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
_Predicate __pred, std::forward_iterator_tag) _Predicate __pred, std::forward_iterator_tag)
...@@ -270,31 +274,26 @@ namespace __gnu_debug ...@@ -270,31 +274,26 @@ namespace __gnu_debug
// Determine if a sequence is sorted. // Determine if a sequence is sorted.
template<typename _InputIterator> template<typename _InputIterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted(const _InputIterator& __first, const _InputIterator& __last) __check_sorted(const _InputIterator& __first, const _InputIterator& __last)
{ {
// Verify that the < operator for elements in the sequence is a
// StrictWeakOrdering by checking that it is irreflexive.
__glibcxx_assert(__first == __last || !(*__first < *__first));
return __check_sorted_aux(__first, __last, return __check_sorted_aux(__first, __last,
std::__iterator_category(__first)); std::__iterator_category(__first));
} }
template<typename _InputIterator, typename _Predicate> template<typename _InputIterator, typename _Predicate>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted(const _InputIterator& __first, const _InputIterator& __last, __check_sorted(const _InputIterator& __first, const _InputIterator& __last,
_Predicate __pred) _Predicate __pred)
{ {
// Verify that the predicate is StrictWeakOrdering by checking that it
// is irreflexive.
__glibcxx_assert(__first == __last || !__pred(*__first, *__first));
return __check_sorted_aux(__first, __last, __pred, return __check_sorted_aux(__first, __last, __pred,
std::__iterator_category(__first)); std::__iterator_category(__first));
} }
template<typename _InputIterator> template<typename _InputIterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_set_aux(const _InputIterator& __first, __check_sorted_set_aux(const _InputIterator& __first,
const _InputIterator& __last, const _InputIterator& __last,
...@@ -302,6 +301,7 @@ namespace __gnu_debug ...@@ -302,6 +301,7 @@ namespace __gnu_debug
{ return __check_sorted(__first, __last); } { return __check_sorted(__first, __last); }
template<typename _InputIterator> template<typename _InputIterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_set_aux(const _InputIterator&, __check_sorted_set_aux(const _InputIterator&,
const _InputIterator&, const _InputIterator&,
...@@ -309,6 +309,7 @@ namespace __gnu_debug ...@@ -309,6 +309,7 @@ namespace __gnu_debug
{ return true; } { return true; }
template<typename _InputIterator, typename _Predicate> template<typename _InputIterator, typename _Predicate>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_set_aux(const _InputIterator& __first, __check_sorted_set_aux(const _InputIterator& __first,
const _InputIterator& __last, const _InputIterator& __last,
...@@ -316,6 +317,7 @@ namespace __gnu_debug ...@@ -316,6 +317,7 @@ namespace __gnu_debug
{ return __check_sorted(__first, __last, __pred); } { return __check_sorted(__first, __last, __pred); }
template<typename _InputIterator, typename _Predicate> template<typename _InputIterator, typename _Predicate>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_set_aux(const _InputIterator&, __check_sorted_set_aux(const _InputIterator&,
const _InputIterator&, _Predicate, const _InputIterator&, _Predicate,
...@@ -324,6 +326,7 @@ namespace __gnu_debug ...@@ -324,6 +326,7 @@ namespace __gnu_debug
// ... special variant used in std::merge, std::includes, std::set_*. // ... special variant used in std::merge, std::includes, std::set_*.
template<typename _InputIterator1, typename _InputIterator2> template<typename _InputIterator1, typename _InputIterator2>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_set(const _InputIterator1& __first, __check_sorted_set(const _InputIterator1& __first,
const _InputIterator1& __last, const _InputIterator1& __last,
...@@ -341,6 +344,7 @@ namespace __gnu_debug ...@@ -341,6 +344,7 @@ namespace __gnu_debug
template<typename _InputIterator1, typename _InputIterator2, template<typename _InputIterator1, typename _InputIterator2,
typename _Predicate> typename _Predicate>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_sorted_set(const _InputIterator1& __first, __check_sorted_set(const _InputIterator1& __first,
const _InputIterator1& __last, const _InputIterator1& __last,
...@@ -360,6 +364,7 @@ namespace __gnu_debug ...@@ -360,6 +364,7 @@ namespace __gnu_debug
// 270. Binary search requirements overly strict // 270. Binary search requirements overly strict
// Determine if a sequence is partitioned w.r.t. this element. // Determine if a sequence is partitioned w.r.t. this element.
template<typename _ForwardIterator, typename _Tp> template<typename _ForwardIterator, typename _Tp>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_partitioned_lower(_ForwardIterator __first, __check_partitioned_lower(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value) _ForwardIterator __last, const _Tp& __value)
...@@ -376,6 +381,7 @@ namespace __gnu_debug ...@@ -376,6 +381,7 @@ namespace __gnu_debug
} }
template<typename _ForwardIterator, typename _Tp> template<typename _ForwardIterator, typename _Tp>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_partitioned_upper(_ForwardIterator __first, __check_partitioned_upper(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value) _ForwardIterator __last, const _Tp& __value)
...@@ -393,6 +399,7 @@ namespace __gnu_debug ...@@ -393,6 +399,7 @@ namespace __gnu_debug
// Determine if a sequence is partitioned w.r.t. this element. // Determine if a sequence is partitioned w.r.t. this element.
template<typename _ForwardIterator, typename _Tp, typename _Pred> template<typename _ForwardIterator, typename _Tp, typename _Pred>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_partitioned_lower(_ForwardIterator __first, __check_partitioned_lower(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value, _ForwardIterator __last, const _Tp& __value,
...@@ -410,6 +417,7 @@ namespace __gnu_debug ...@@ -410,6 +417,7 @@ namespace __gnu_debug
} }
template<typename _ForwardIterator, typename _Tp, typename _Pred> template<typename _ForwardIterator, typename _Tp, typename _Pred>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__check_partitioned_upper(_ForwardIterator __first, __check_partitioned_upper(_ForwardIterator __first,
_ForwardIterator __last, const _Tp& __value, _ForwardIterator __last, const _Tp& __value,
...@@ -435,35 +443,41 @@ namespace __gnu_debug ...@@ -435,35 +443,41 @@ namespace __gnu_debug
template<typename _It, template<typename _It,
typename = decltype(__deref<_It>() < __deref<_It>())> typename = decltype(__deref<_It>() < __deref<_It>())>
_GLIBCXX20_CONSTEXPR
static bool static bool
_S_is_valid(_It __it) _S_is_valid(_It __it)
{ return !(*__it < *__it); } { return !(*__it < *__it); }
// Fallback method if operator doesn't exist. // Fallback method if operator doesn't exist.
template<typename... _Args> template<typename... _Args>
_GLIBCXX20_CONSTEXPR
static bool static bool
_S_is_valid(_Args...) _S_is_valid(_Args...)
{ return true; } { return true; }
template<typename _It, typename _Pred, typename template<typename _It, typename _Pred, typename
= decltype(std::declval<_Pred>()(__deref<_It>(), __deref<_It>()))> = decltype(std::declval<_Pred>()(__deref<_It>(), __deref<_It>()))>
_GLIBCXX20_CONSTEXPR
static bool static bool
_S_is_valid_pred(_It __it, _Pred __pred) _S_is_valid_pred(_It __it, _Pred __pred)
{ return !__pred(*__it, *__it); } { return !__pred(*__it, *__it); }
// Fallback method if predicate can't be invoked. // Fallback method if predicate can't be invoked.
template<typename... _Args> template<typename... _Args>
_GLIBCXX20_CONSTEXPR
static bool static bool
_S_is_valid_pred(_Args...) _S_is_valid_pred(_Args...)
{ return true; } { return true; }
}; };
template<typename _Iterator> template<typename _Iterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__is_irreflexive(_Iterator __it) __is_irreflexive(_Iterator __it)
{ return _Irreflexive_checker::_S_is_valid(__it); } { return _Irreflexive_checker::_S_is_valid(__it); }
template<typename _Iterator, typename _Pred> template<typename _Iterator, typename _Pred>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__is_irreflexive_pred(_Iterator __it, _Pred __pred) __is_irreflexive_pred(_Iterator __it, _Pred __pred)
{ return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); } { return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }
......
...@@ -87,12 +87,14 @@ namespace __gnu_debug ...@@ -87,12 +87,14 @@ namespace __gnu_debug
* precision. * precision.
*/ */
template<typename _Iterator> template<typename _Iterator>
_GLIBCXX_CONSTEXPR
inline typename _Distance_traits<_Iterator>::__type inline typename _Distance_traits<_Iterator>::__type
__get_distance(_Iterator __lhs, _Iterator __rhs, __get_distance(_Iterator __lhs, _Iterator __rhs,
std::random_access_iterator_tag) std::random_access_iterator_tag)
{ return std::make_pair(__rhs - __lhs, __dp_exact); } { return std::make_pair(__rhs - __lhs, __dp_exact); }
template<typename _Iterator> template<typename _Iterator>
_GLIBCXX_CONSTEXPR
inline typename _Distance_traits<_Iterator>::__type inline typename _Distance_traits<_Iterator>::__type
__get_distance(_Iterator __lhs, _Iterator __rhs, __get_distance(_Iterator __lhs, _Iterator __rhs,
std::input_iterator_tag) std::input_iterator_tag)
...@@ -104,6 +106,7 @@ namespace __gnu_debug ...@@ -104,6 +106,7 @@ namespace __gnu_debug
} }
template<typename _Iterator> template<typename _Iterator>
_GLIBCXX_CONSTEXPR
inline typename _Distance_traits<_Iterator>::__type inline typename _Distance_traits<_Iterator>::__type
__get_distance(_Iterator __lhs, _Iterator __rhs) __get_distance(_Iterator __lhs, _Iterator __rhs)
{ return __get_distance(__lhs, __rhs, std::__iterator_category(__lhs)); } { return __get_distance(__lhs, __rhs, std::__iterator_category(__lhs)); }
...@@ -113,6 +116,13 @@ namespace __gnu_debug ...@@ -113,6 +116,13 @@ namespace __gnu_debug
* iterators. * iterators.
*/ */
template<typename _Integral> template<typename _Integral>
_GLIBCXX_CONSTEXPR
inline bool
__valid_range_aux(_Integral, _Integral, std::__true_type)
{ return true; }
template<typename _Integral>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__valid_range_aux(_Integral, _Integral, __valid_range_aux(_Integral, _Integral,
typename _Distance_traits<_Integral>::__type& __dist, typename _Distance_traits<_Integral>::__type& __dist,
...@@ -122,10 +132,35 @@ namespace __gnu_debug ...@@ -122,10 +132,35 @@ namespace __gnu_debug
return true; return true;
} }
template<typename _InputIterator>
_GLIBCXX_CONSTEXPR
inline bool
__valid_range_aux(_InputIterator __first, _InputIterator __last,
std::input_iterator_tag)
{ return true; }
template<typename _InputIterator>
_GLIBCXX_CONSTEXPR
inline bool
__valid_range_aux(_InputIterator __first, _InputIterator __last,
std::random_access_iterator_tag)
{ return __first <= __last; }
/** We have iterators, so figure out what kind of iterators they are /** We have iterators, so figure out what kind of iterators they are
* to see if we can check the range ahead of time. * to see if we can check the range ahead of time.
*/ */
template<typename _InputIterator> template<typename _InputIterator>
_GLIBCXX_CONSTEXPR
inline bool
__valid_range_aux(_InputIterator __first, _InputIterator __last,
std::__false_type)
{
return __valid_range_aux(__first, __last,
std::__iterator_category(__first));
}
template<typename _InputIterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__valid_range_aux(_InputIterator __first, _InputIterator __last, __valid_range_aux(_InputIterator __first, _InputIterator __last,
typename _Distance_traits<_InputIterator>::__type& __dist, typename _Distance_traits<_InputIterator>::__type& __dist,
...@@ -155,10 +190,16 @@ namespace __gnu_debug ...@@ -155,10 +190,16 @@ namespace __gnu_debug
* otherwise. * otherwise.
*/ */
template<typename _InputIterator> template<typename _InputIterator>
_GLIBCXX20_CONSTEXPR
inline bool inline bool
__valid_range(_InputIterator __first, _InputIterator __last, __valid_range(_InputIterator __first, _InputIterator __last,
typename _Distance_traits<_InputIterator>::__type& __dist) typename _Distance_traits<_InputIterator>::__type& __dist)
{ {
#ifdef __cpp_lib_is_constant_evaluated
if (std::is_constant_evaluated())
// Detected by the compiler directly.
return true;
#endif
typedef typename std::__is_integer<_InputIterator>::__type _Integral; typedef typename std::__is_integer<_InputIterator>::__type _Integral;
return __valid_range_aux(__first, __last, __dist, _Integral()); return __valid_range_aux(__first, __last, __dist, _Integral());
} }
...@@ -178,11 +219,17 @@ namespace __gnu_debug ...@@ -178,11 +219,17 @@ namespace __gnu_debug
#endif #endif
template<typename _InputIterator> template<typename _InputIterator>
_GLIBCXX_CONSTEXPR
inline bool inline bool
__valid_range(_InputIterator __first, _InputIterator __last) __valid_range(_InputIterator __first, _InputIterator __last)
{ {
typename _Distance_traits<_InputIterator>::__type __dist; #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
return __valid_range(__first, __last, __dist); if (__builtin_is_constant_evaluated())
// Detected by the compiler directly.
return true;
#endif
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
return __valid_range_aux(__first, __last, _Integral());
} }
template<typename _Iterator, typename _Sequence, typename _Category> template<typename _Iterator, typename _Sequence, typename _Category>
...@@ -199,6 +246,7 @@ namespace __gnu_debug ...@@ -199,6 +246,7 @@ namespace __gnu_debug
// Fallback method, always ok. // Fallback method, always ok.
template<typename _InputIterator, typename _Size> template<typename _InputIterator, typename _Size>
_GLIBCXX_CONSTEXPR
inline bool inline bool
__can_advance(_InputIterator, _Size) __can_advance(_InputIterator, _Size)
{ return true; } { return true; }
...@@ -216,6 +264,7 @@ namespace __gnu_debug ...@@ -216,6 +264,7 @@ namespace __gnu_debug
* thanks to the < operator. * thanks to the < operator.
*/ */
template<typename _Iterator> template<typename _Iterator>
_GLIBCXX_CONSTEXPR
inline _Iterator inline _Iterator
__base(_Iterator __it) __base(_Iterator __it)
{ return __it; } { return __it; }
......
...@@ -38,10 +38,20 @@ ...@@ -38,10 +38,20 @@
* the user error and where the error is reported. * the user error and where the error is reported.
* *
*/ */
#define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \ #if 0 /* defined _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED */
# define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
if (__builtin_is_constant_evaluated()) \
/* FIXME: Compilation error here when !_Cond. */ \
break; \
if (! (_Cond)) \ if (! (_Cond)) \
__gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \ __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
._ErrMsg._M_error() ._ErrMsg._M_error()
#else
# define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
if (! (_Cond)) \
__gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
._ErrMsg._M_error()
#endif
#define _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,_Func) \ #define _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,_Func) \
do \ do \
...@@ -291,9 +301,43 @@ _GLIBCXX_DEBUG_VERIFY(! this->empty(), \ ...@@ -291,9 +301,43 @@ _GLIBCXX_DEBUG_VERIFY(! this->empty(), \
_M_message(__gnu_debug::__msg_empty) \ _M_message(__gnu_debug::__msg_empty) \
._M_sequence(*this, "this")) ._M_sequence(*this, "this"))
// Verify that a predicate is irreflexive
#define __glibcxx_check_irreflexive(_First,_Last) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last || !(*_First < *_First), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_iterator_value_type(_First, "< operator type"))
#if __cplusplus >= 201103L
# define __glibcxx_check_irreflexive2(_First,_Last) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last \
|| __gnu_debug::__is_irreflexive(_First), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_iterator_value_type(_First, "< operator type"))
#else
# define __glibcxx_check_irreflexive2(_First,_Last)
#endif
#define __glibcxx_check_irreflexive_pred(_First,_Last,_Pred) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last || !_Pred(*_First, *_First), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_instance(_Pred, "functor") \
._M_iterator_value_type(_First, "ordered type"))
#if __cplusplus >= 201103L
# define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last \
||__gnu_debug::__is_irreflexive_pred(_First, _Pred), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_instance(_Pred, "functor") \
._M_iterator_value_type(_First, "ordered type"))
#else
# define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred)
#endif
// Verify that the iterator range [_First, _Last) is sorted // Verify that the iterator range [_First, _Last) is sorted
#define __glibcxx_check_sorted(_First,_Last) \ #define __glibcxx_check_sorted(_First,_Last) \
__glibcxx_check_valid_range(_First,_Last); \ __glibcxx_check_valid_range(_First,_Last); \
__glibcxx_check_irreflexive(_First,_Last); \
_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
__gnu_debug::__base(_First), \ __gnu_debug::__base(_First), \
__gnu_debug::__base(_Last)), \ __gnu_debug::__base(_Last)), \
...@@ -305,6 +349,7 @@ __glibcxx_check_valid_range(_First,_Last); \ ...@@ -305,6 +349,7 @@ __glibcxx_check_valid_range(_First,_Last); \
predicate _Pred. */ predicate _Pred. */
#define __glibcxx_check_sorted_pred(_First,_Last,_Pred) \ #define __glibcxx_check_sorted_pred(_First,_Last,_Pred) \
__glibcxx_check_valid_range(_First,_Last); \ __glibcxx_check_valid_range(_First,_Last); \
__glibcxx_check_irreflexive_pred(_First,_Last,_Pred); \
_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted( \
__gnu_debug::__base(_First), \ __gnu_debug::__base(_First), \
__gnu_debug::__base(_Last), _Pred), \ __gnu_debug::__base(_Last), _Pred), \
...@@ -423,37 +468,4 @@ _GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(), \ ...@@ -423,37 +468,4 @@ _GLIBCXX_DEBUG_VERIFY(_This.get_allocator() == _Other.get_allocator(), \
#define __glibcxx_check_string_len(_String,_Len) \ #define __glibcxx_check_string_len(_String,_Len) \
_GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0) _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0)
// Verify that a predicate is irreflexive
#define __glibcxx_check_irreflexive(_First,_Last) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last || !(*_First < *_First), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_iterator_value_type(_First, "< operator type"))
#if __cplusplus >= 201103L
# define __glibcxx_check_irreflexive2(_First,_Last) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last \
|| __gnu_debug::__is_irreflexive(_First), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_iterator_value_type(_First, "< operator type"))
#else
# define __glibcxx_check_irreflexive2(_First,_Last)
#endif
#define __glibcxx_check_irreflexive_pred(_First,_Last,_Pred) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last || !_Pred(*_First, *_First), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_instance(_Pred, "functor") \
._M_iterator_value_type(_First, "ordered type"))
#if __cplusplus >= 201103L
# define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred) \
_GLIBCXX_DEBUG_VERIFY(_First == _Last \
||__gnu_debug::__is_irreflexive_pred(_First, _Pred), \
_M_message(__gnu_debug::__msg_irreflexive_ordering) \
._M_instance(_Pred, "functor") \
._M_iterator_value_type(_First, "ordered type"))
#else
# define __glibcxx_check_irreflexive_pred2(_First,_Last,_Pred)
#endif
#endif #endif
...@@ -29,7 +29,7 @@ test() ...@@ -29,7 +29,7 @@ test()
const auto out4 = std::binary_search(ca0.begin(), ca0.end(), 5); const auto out4 = std::binary_search(ca0.begin(), ca0.end(), 5);
const auto out5 = std::binary_search(ca0.begin(), ca0.end(), 5, const auto out5 = std::binary_search(ca0.begin(), ca0.end(), 5,
std::equal_to<int>()); std::less<int>());
return true; return true;
} }
......
...@@ -26,7 +26,7 @@ constexpr std::array<int, 12> ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; ...@@ -26,7 +26,7 @@ constexpr std::array<int, 12> ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
constexpr auto outv = std::is_sorted(ca0.begin(), ca0.end()); constexpr auto outv = std::is_sorted(ca0.begin(), ca0.end());
constexpr auto outw = std::is_sorted(ca0.begin(), ca0.end(), constexpr auto outw = std::is_sorted(ca0.begin(), ca0.end(),
std::equal_to<int>()); std::less<int>());
constexpr bool constexpr bool
test() test()
......
...@@ -26,7 +26,7 @@ test() ...@@ -26,7 +26,7 @@ test()
{ {
constexpr std::array<int, 12> ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; constexpr std::array<int, 12> ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
constexpr std::array<int, 12> cas{{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}}; constexpr std::array<int, 12> cas{{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}};
constexpr std::array<int, 3> camm{{-4, -5, -6}}; constexpr std::array<int, 3> camm{{-6, -5, -4}};
std::array<int, 24> out0{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; std::array<int, 24> out0{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
const auto outdd = std::merge(ca0.begin(), ca0.end(), const auto outdd = std::merge(ca0.begin(), ca0.end(),
...@@ -34,7 +34,7 @@ test() ...@@ -34,7 +34,7 @@ test()
const auto outee = std::merge(ca0.begin(), ca0.end(), const auto outee = std::merge(ca0.begin(), ca0.end(),
camm.begin(), camm.end(), out0.begin(), camm.begin(), camm.end(), out0.begin(),
[](int i, int j){ return i < -j; }); [](int i, int j){ return i < j; });
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment