// Debugging support implementation -*- C++ -*-
-// Copyright (C) 2003, 2005
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING. If not, write to the Free
-// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/functions.h
+ * This file is a GNU debug extension to the Standard C++ Library.
+ */
#ifndef _GLIBCXX_DEBUG_FUNCTIONS_H
#define _GLIBCXX_DEBUG_FUNCTIONS_H 1
#include <bits/c++config.h>
-#include <stddef.h> // for ptrdiff_t
+#include <cstddef> // for ptrdiff_t
#include <bits/stl_iterator_base_types.h> // for iterator_traits, categories
#include <bits/cpp_type_traits.h> // for __is_integer
-namespace std
-{
namespace __gnu_debug
{
template<typename _Iterator, typename _Sequence>
*/
template<typename _Integral>
inline bool
- __valid_range_aux(const _Integral&, const _Integral&, __true_type)
+ __valid_range_aux(const _Integral&, const _Integral&, std::__true_type)
{ return true; }
/** We have iterators, so figure out what kind of iterators that are
template<typename _InputIterator>
inline bool
__valid_range_aux(const _InputIterator& __first,
- const _InputIterator& __last, __false_type)
+ const _InputIterator& __last, std::__false_type)
{
typedef typename std::iterator_traits<_InputIterator>::iterator_category
_Category;
return true;
_ForwardIterator __next = __first;
- for (++__next; __next != __last; __first = __next, ++__next) {
+ for (++__next; __next != __last; __first = __next, ++__next)
if (*__next < *__first)
return false;
- }
return true;
}
return true;
_ForwardIterator __next = __first;
- for (++__next; __next != __last; __first = __next, ++__next) {
+ for (++__next; __next != __last; __first = __next, ++__next)
if (__pred(*__next, *__first))
return false;
- }
return true;
}
{
typedef typename std::iterator_traits<_InputIterator>::iterator_category
_Category;
+
+ // Verify that the < operator for elements in the sequence is a
+ // StrictWeakOrdering by checking that it is irreflexive.
+ _GLIBCXX_DEBUG_ASSERT(__first == __last || !(*__first < *__first));
+
return __check_sorted_aux(__first, __last, _Category());
}
{
typedef typename std::iterator_traits<_InputIterator>::iterator_category
_Category;
- return __check_sorted_aux(__first, __last, __pred,
- _Category());
+
+ // Verify that the predicate is StrictWeakOrdering by checking that it
+ // is irreflexive.
+ _GLIBCXX_DEBUG_ASSERT(__first == __last || !__pred(*__first, *__first));
+
+ return __check_sorted_aux(__first, __last, __pred, _Category());
+ }
+
+ template<typename _InputIterator>
+ inline bool
+ __check_sorted_set_aux(const _InputIterator& __first,
+ const _InputIterator& __last,
+ std::__true_type)
+ { return __check_sorted(__first, __last); }
+
+ template<typename _InputIterator>
+ inline bool
+ __check_sorted_set_aux(const _InputIterator&,
+ const _InputIterator&,
+ std::__false_type)
+ { return true; }
+
+ template<typename _InputIterator, typename _Predicate>
+ inline bool
+ __check_sorted_set_aux(const _InputIterator& __first,
+ const _InputIterator& __last,
+ _Predicate __pred, std::__true_type)
+ { return __check_sorted(__first, __last, __pred); }
+
+ template<typename _InputIterator, typename _Predicate>
+ inline bool
+ __check_sorted_set_aux(const _InputIterator&,
+ const _InputIterator&, _Predicate,
+ std::__false_type)
+ { return true; }
+
+ // ... special variant used in std::merge, std::includes, std::set_*.
+ template<typename _InputIterator1, typename _InputIterator2>
+ inline bool
+ __check_sorted_set(const _InputIterator1& __first,
+ const _InputIterator1& __last,
+ const _InputIterator2&)
+ {
+ typedef typename std::iterator_traits<_InputIterator1>::value_type
+ _ValueType1;
+ typedef typename std::iterator_traits<_InputIterator2>::value_type
+ _ValueType2;
+
+ typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
+ _SameType;
+ return __check_sorted_set_aux(__first, __last, _SameType());
}
+ template<typename _InputIterator1, typename _InputIterator2,
+ typename _Predicate>
+ inline bool
+ __check_sorted_set(const _InputIterator1& __first,
+ const _InputIterator1& __last,
+ const _InputIterator2&, _Predicate __pred)
+ {
+ typedef typename std::iterator_traits<_InputIterator1>::value_type
+ _ValueType1;
+ typedef typename std::iterator_traits<_InputIterator2>::value_type
+ _ValueType2;
+
+ typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
+ _SameType;
+ return __check_sorted_set_aux(__first, __last, __pred, _SameType());
+ }
+
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 270. Binary search requirements overly strict
// Determine if a sequence is partitioned w.r.t. this element.
template<typename _ForwardIterator, typename _Tp>
inline bool
- __check_partitioned(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __value)
+ __check_partitioned_lower(_ForwardIterator __first,
+ _ForwardIterator __last, const _Tp& __value)
{
while (__first != __last && *__first < __value)
++__first;
return __first == __last;
}
+ template<typename _ForwardIterator, typename _Tp>
+ inline bool
+ __check_partitioned_upper(_ForwardIterator __first,
+ _ForwardIterator __last, const _Tp& __value)
+ {
+ while (__first != __last && !(__value < *__first))
+ ++__first;
+ while (__first != __last && __value < *__first)
+ ++__first;
+ return __first == __last;
+ }
+
// Determine if a sequence is partitioned w.r.t. this element.
template<typename _ForwardIterator, typename _Tp, typename _Pred>
inline bool
- __check_partitioned(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __value, _Pred __pred)
+ __check_partitioned_lower(_ForwardIterator __first,
+ _ForwardIterator __last, const _Tp& __value,
+ _Pred __pred)
+ {
+ while (__first != __last && bool(__pred(*__first, __value)))
+ ++__first;
+ while (__first != __last && !bool(__pred(*__first, __value)))
+ ++__first;
+ return __first == __last;
+ }
+
+ template<typename _ForwardIterator, typename _Tp, typename _Pred>
+ inline bool
+ __check_partitioned_upper(_ForwardIterator __first,
+ _ForwardIterator __last, const _Tp& __value,
+ _Pred __pred)
{
- while (__first != __last && __pred(*__first, __value))
+ while (__first != __last && !bool(__pred(__value, *__first)))
++__first;
- while (__first != __last && !__pred(*__first, __value))
+ while (__first != __last && bool(__pred(__value, *__first)))
++__first;
return __first == __last;
}
} // namespace __gnu_debug
-} // namespace std
#endif