annotate build-aux/stl_algo.h-fixed @ 20654:b65888ec820e draft default tip gccjit

dmalcom gcc jit import
author Stefan Mahr <dac922@gmx.de>
date Fri, 27 Feb 2015 16:59:36 +0100
parents 0d660785098e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17878
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 // Algorithm implementation -*- C++ -*-
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 // Copyright (C) 2001-2013 Free Software Foundation, Inc.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 //
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 // This file is part of the GNU ISO C++ Library. This library is free
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 // software; you can redistribute it and/or modify it under the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 // terms of the GNU General Public License as published by the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 // Free Software Foundation; either version 3, or (at your option)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 // any later version.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 // This library is distributed in the hope that it will be useful,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 // GNU General Public License for more details.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 /*
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 * Copyright (c) 1994
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 * Hewlett-Packard Company
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 * Permission to use, copy, modify, distribute and sell this software
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 * and its documentation for any purpose is hereby granted without fee,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 * provided that the above copyright notice appear in all copies and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 * that both that copyright notice and this permission notice appear
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 * in supporting documentation. Hewlett-Packard Company makes no
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 * representations about the suitability of this software for any
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 * purpose. It is provided "as is" without express or implied warranty.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 * Copyright (c) 1996
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 * Silicon Graphics Computer Systems, Inc.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 * Permission to use, copy, modify, distribute and sell this software
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 * and its documentation for any purpose is hereby granted without fee,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 * provided that the above copyright notice appear in all copies and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 * that both that copyright notice and this permission notice appear
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 * in supporting documentation. Silicon Graphics makes no
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 * representations about the suitability of this software for any
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 * purpose. It is provided "as is" without express or implied warranty.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 /** @file bits/stl_algo.h
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 * This is an internal header file, included by other library headers.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 * Do not attempt to use it directly. @headername{algorithm}
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 #ifndef _STL_ALGO_H
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 #define _STL_ALGO_H 1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 #include <cstdlib> // for rand
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 #include <bits/algorithmfwd.h>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 #include <bits/stl_heap.h>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 #include <bits/stl_tempbuf.h> // for _Temporary_buffer
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 #if __cplusplus >= 201103L
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 #include <random> // for std::uniform_int_distribution
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 #include <functional> // for std::bind
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 #endif
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 // See concept_check.h for the __glibcxx_*_requires macros.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 namespace std _GLIBCXX_VISIBILITY(default)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 _GLIBCXX_BEGIN_NAMESPACE_VERSION
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 /// Swaps the median value of *__a, *__b and *__c to *__result
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 template<typename _Iterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 __move_median_to_first(_Iterator __result, _Iterator __a,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 _Iterator __b, _Iterator __c)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 __glibcxx_function_requires(_LessThanComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 typename iterator_traits<_Iterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 if (*__a < *__b)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 if (*__b < *__c)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 std::iter_swap(__result, __b);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 else if (*__a < *__c)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 std::iter_swap(__result, __c);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 std::iter_swap(__result, __a);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 else if (*__a < *__c)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 std::iter_swap(__result, __a);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 else if (*__b < *__c)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 std::iter_swap(__result, __c);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 std::iter_swap(__result, __b);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 /// Swaps the median value of *__a, *__b and *__c under __comp to *__result
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 template<typename _Iterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 __move_median_to_first(_Iterator __result, _Iterator __a,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 _Iterator __b, _Iterator __c,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 __glibcxx_function_requires(_BinaryFunctionConcept<_Compare, bool,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 typename iterator_traits<_Iterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 typename iterator_traits<_Iterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 if (__comp(*__a, *__b))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 if (__comp(*__b, *__c))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 std::iter_swap(__result, __b);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 else if (__comp(*__a, *__c))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 std::iter_swap(__result, __c);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 std::iter_swap(__result, __a);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 else if (__comp(*__a, *__c))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 std::iter_swap(__result, __a);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 else if (__comp(*__b, *__c))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 std::iter_swap(__result, __c);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 std::iter_swap(__result, __b);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 // for_each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 /// This is an overload used by find() for the Input Iterator case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 template<typename _InputIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 inline _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 __find(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 const _Tp& __val, input_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 while (__first != __last && !(*__first == __val))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 /// This is an overload used by find_if() for the Input Iterator case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 inline _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 __find_if(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 _Predicate __pred, input_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 while (__first != __last && !bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 /// This is an overload used by find() for the RAI case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 template<typename _RandomAccessIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 __find(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 const _Tp& __val, random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 __trip_count = (__last - __first) >> 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 for (; __trip_count > 0; --__trip_count)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 if (*__first == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 if (*__first == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 if (*__first == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 if (*__first == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 switch (__last - __first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 case 3:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 if (*__first == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 case 2:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 if (*__first == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 case 1:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 if (*__first == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 case 0:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 default:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 /// This is an overload used by find_if() for the RAI case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 template<typename _RandomAccessIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 _Predicate __pred, random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 __trip_count = (__last - __first) >> 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 for (; __trip_count > 0; --__trip_count)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 switch (__last - __first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 case 3:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 case 2:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 case 1:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 case 0:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 default:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251 /// This is an overload used by find_if_not() for the Input Iterator case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253 inline _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 __find_if_not(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 _Predicate __pred, input_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 while (__first != __last && bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262 /// This is an overload used by find_if_not() for the RAI case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 template<typename _RandomAccessIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264 _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265 __find_if_not(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266 _Predicate __pred, random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
267 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269 __trip_count = (__last - __first) >> 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 for (; __trip_count > 0; --__trip_count)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
277 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
281 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
282 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290 switch (__last - __first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
292 case 3:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296 case 2:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
298 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300 case 1:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 case 0:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305 default:
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 /// Provided for stable_partition to use.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 inline _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 __find_if_not(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
314 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316 return std::__find_if_not(__first, __last, __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317 std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 /// Like find_if_not(), but uses and updates a count of the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 /// remaining range length instead of comparing against an end
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 /// iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323 template<typename _InputIterator, typename _Predicate, typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325 __find_if_not_n(_InputIterator __first, _Distance& __len, _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327 for (; __len; --__len, ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
330 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
333 // set_difference
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334 // set_intersection
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335 // set_symmetric_difference
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336 // set_union
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
337 // for_each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
338 // find
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
339 // find_if
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340 // find_first_of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341 // adjacent_find
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
342 // count
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 // count_if
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344 // search
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 * This is an uglified
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
348 * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349 * overloaded for forward iterators.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351 template<typename _ForwardIterator, typename _Integer, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
353 __search_n(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354 _Integer __count, const _Tp& __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 std::forward_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 __first = _GLIBCXX_STD_A::find(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 while (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
359 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 __n = __count;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362 _ForwardIterator __i = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 while (__i != __last && __n != 1 && *__i == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
367 --__n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
369 if (__n == 1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
370 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
371 if (__i == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373 __first = _GLIBCXX_STD_A::find(++__i, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
375 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
376 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
378 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379 * This is an uglified
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
380 * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381 * overloaded for random access iterators.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383 template<typename _RandomAccessIter, typename _Integer, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384 _RandomAccessIter
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 __search_n(_RandomAccessIter __first, _RandomAccessIter __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
386 _Integer __count, const _Tp& __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
387 std::random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
389
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
390 typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
392
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
393 _DistanceType __tailSize = __last - __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
394 _DistanceType __remainder = __count;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396 while (__remainder <= __tailSize) // the main loop...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398 __first += __remainder;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399 __tailSize -= __remainder;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
400 // __first here is always pointing to one past the last element of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401 // next possible match.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402 _RandomAccessIter __backTrack = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 while (*--__backTrack == __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
404 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 if (--__remainder == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406 return (__first - __count); // Success
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 __remainder = __count + 1 - (__first - __backTrack);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
410 return __last; // Failure
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
413 // search_n
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 * This is an uglified
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418 * _BinaryPredicate)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419 * overloaded for forward iterators.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421 template<typename _ForwardIterator, typename _Integer, typename _Tp,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424 __search_n(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
425 _Integer __count, const _Tp& __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
426 _BinaryPredicate __binary_pred, std::forward_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428 while (__first != __last && !bool(__binary_pred(*__first, __val)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
429 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 while (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434 __n = __count;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435 _ForwardIterator __i = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437 while (__i != __last && __n != 1 && bool(__binary_pred(*__i, __val)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
439 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440 --__n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442 if (__n == 1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
443 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
444 if (__i == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
446 __first = ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
447 while (__first != __last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
448 && !bool(__binary_pred(*__first, __val)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
449 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
450 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
452 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
453
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
454 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
455 * This is an uglified
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
456 * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
457 * _BinaryPredicate)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
458 * overloaded for random access iterators.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
460 template<typename _RandomAccessIter, typename _Integer, typename _Tp,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
461 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
462 _RandomAccessIter
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
463 __search_n(_RandomAccessIter __first, _RandomAccessIter __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
464 _Integer __count, const _Tp& __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
465 _BinaryPredicate __binary_pred, std::random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
466 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
467
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
468 typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
470
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
471 _DistanceType __tailSize = __last - __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
472 _DistanceType __remainder = __count;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
473
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
474 while (__remainder <= __tailSize) // the main loop...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
475 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
476 __first += __remainder;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
477 __tailSize -= __remainder;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
478 // __first here is always pointing to one past the last element of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
479 // next possible match.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
480 _RandomAccessIter __backTrack = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
481 while (__binary_pred(*--__backTrack, __val))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
482 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
483 if (--__remainder == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
484 return (__first - __count); // Success
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
485 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
486 __remainder = __count + 1 - (__first - __backTrack);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
487 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488 return __last; // Failure
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
489 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
490
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
491 // find_end for forward iterators.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
492 template<typename _ForwardIterator1, typename _ForwardIterator2>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493 _ForwardIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
494 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
495 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
496 forward_iterator_tag, forward_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
497 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
498 if (__first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
499 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
500 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
501 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
502 _ForwardIterator1 __result = __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
503 while (1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
505 _ForwardIterator1 __new_result
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
506 = _GLIBCXX_STD_A::search(__first1, __last1, __first2, __last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
507 if (__new_result == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
508 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
509 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
510 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
511 __result = __new_result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
512 __first1 = __new_result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
513 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
514 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
515 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
516 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
517 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
518
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
519 template<typename _ForwardIterator1, typename _ForwardIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
520 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
521 _ForwardIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
522 __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
523 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
524 forward_iterator_tag, forward_iterator_tag,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525 _BinaryPredicate __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
526 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
527 if (__first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
528 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
529 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
530 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
531 _ForwardIterator1 __result = __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
532 while (1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
533 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534 _ForwardIterator1 __new_result
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
535 = _GLIBCXX_STD_A::search(__first1, __last1, __first2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536 __last2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
537 if (__new_result == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
538 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
540 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
541 __result = __new_result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542 __first1 = __new_result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
543 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
544 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
545 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
546 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
547 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
548
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
549 // find_end for bidirectional iterators (much faster).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
550 template<typename _BidirectionalIterator1, typename _BidirectionalIterator2>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551 _BidirectionalIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
552 __find_end(_BidirectionalIterator1 __first1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
553 _BidirectionalIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
554 _BidirectionalIterator2 __first2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
555 _BidirectionalIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
556 bidirectional_iterator_tag, bidirectional_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
557 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
558 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
560 _BidirectionalIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
561 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
562 _BidirectionalIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
563
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
564 typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
565 typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
566
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
567 _RevIterator1 __rlast1(__first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
568 _RevIterator2 __rlast2(__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
569 _RevIterator1 __rresult = _GLIBCXX_STD_A::search(_RevIterator1(__last1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
570 __rlast1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
571 _RevIterator2(__last2),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
572 __rlast2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
573
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
574 if (__rresult == __rlast1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
575 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
576 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
577 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578 _BidirectionalIterator1 __result = __rresult.base();
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
579 std::advance(__result, -std::distance(__first2, __last2));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
580 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
581 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
582 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
583
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
584 template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
585 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
586 _BidirectionalIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
587 __find_end(_BidirectionalIterator1 __first1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
588 _BidirectionalIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
589 _BidirectionalIterator2 __first2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
590 _BidirectionalIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
591 bidirectional_iterator_tag, bidirectional_iterator_tag,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
592 _BinaryPredicate __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
593 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
594 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
595 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
596 _BidirectionalIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
597 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
598 _BidirectionalIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
599
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
600 typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
601 typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
602
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
603 _RevIterator1 __rlast1(__first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
604 _RevIterator2 __rlast2(__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
605 _RevIterator1 __rresult = std::search(_RevIterator1(__last1), __rlast1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
606 _RevIterator2(__last2), __rlast2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
607 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
608
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
609 if (__rresult == __rlast1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
610 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
611 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
612 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
613 _BidirectionalIterator1 __result = __rresult.base();
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
614 std::advance(__result, -std::distance(__first2, __last2));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
615 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
616 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
617 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
618
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
619 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
620 * @brief Find last matching subsequence in a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
621 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
622 * @param __first1 Start of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
623 * @param __last1 End of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
624 * @param __first2 Start of sequence to match.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
625 * @param __last2 End of sequence to match.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
626 * @return The last iterator @c i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
627 * @p [__first1,__last1-(__last2-__first2)) such that @c *(i+N) ==
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
628 * @p *(__first2+N) for each @c N in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
629 * [0,__last2-__first2), or @p __last1 if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
630 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
631 * Searches the range @p [__first1,__last1) for a sub-sequence that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
632 * compares equal value-by-value with the sequence given by @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
633 * [__first2,__last2) and returns an iterator to the __first
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
634 * element of the sub-sequence, or @p __last1 if the sub-sequence
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
635 * is not found. The sub-sequence will be the last such
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
636 * subsequence contained in [__first,__last1).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
637 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
638 * Because the sub-sequence must lie completely within the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
639 * [__first1,__last1) it must start at a position less than @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
640 * __last1-(__last2-__first2) where @p __last2-__first2 is the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
641 * length of the sub-sequence. This means that the returned
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
642 * iterator @c i will be in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
643 * [__first1,__last1-(__last2-__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
644 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
645 template<typename _ForwardIterator1, typename _ForwardIterator2>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
646 inline _ForwardIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
647 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
648 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
649 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
650 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
651 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
652 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
653 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
654 typename iterator_traits<_ForwardIterator1>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
655 typename iterator_traits<_ForwardIterator2>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
656 __glibcxx_requires_valid_range(__first1, __last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
657 __glibcxx_requires_valid_range(__first2, __last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
658
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
659 return std::__find_end(__first1, __last1, __first2, __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
660 std::__iterator_category(__first1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
661 std::__iterator_category(__first2));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
662 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
663
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
664 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
665 * @brief Find last matching subsequence in a sequence using a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
666 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
667 * @param __first1 Start of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
668 * @param __last1 End of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
669 * @param __first2 Start of sequence to match.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
670 * @param __last2 End of sequence to match.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
671 * @param __comp The predicate to use.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
672 * @return The last iterator @c i in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
673 * [__first1,__last1-(__last2-__first2)) such that @c
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
674 * predicate(*(i+N), @p (__first2+N)) is true for each @c N in the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
675 * range @p [0,__last2-__first2), or @p __last1 if no such iterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
676 * exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
677 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
678 * Searches the range @p [__first1,__last1) for a sub-sequence that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
679 * compares equal value-by-value with the sequence given by @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
680 * [__first2,__last2) using comp as a predicate and returns an
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
681 * iterator to the first element of the sub-sequence, or @p __last1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
682 * if the sub-sequence is not found. The sub-sequence will be the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
683 * last such subsequence contained in [__first,__last1).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
684 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
685 * Because the sub-sequence must lie completely within the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
686 * [__first1,__last1) it must start at a position less than @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
687 * __last1-(__last2-__first2) where @p __last2-__first2 is the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
688 * length of the sub-sequence. This means that the returned
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
689 * iterator @c i will be in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
690 * [__first1,__last1-(__last2-__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
691 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
692 template<typename _ForwardIterator1, typename _ForwardIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
693 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
694 inline _ForwardIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
695 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
696 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
697 _BinaryPredicate __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
698 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
699 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
700 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
701 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
702 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
703 typename iterator_traits<_ForwardIterator1>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
704 typename iterator_traits<_ForwardIterator2>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
705 __glibcxx_requires_valid_range(__first1, __last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
706 __glibcxx_requires_valid_range(__first2, __last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
707
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
708 return std::__find_end(__first1, __last1, __first2, __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
709 std::__iterator_category(__first1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
710 std::__iterator_category(__first2),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
711 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
712 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
713
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
714 #if __cplusplus >= 201103L
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
715 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
716 * @brief Checks that a predicate is true for all the elements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
717 * of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
718 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
719 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
720 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
721 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
722 * @return True if the check is true, false otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
723 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
724 * Returns true if @p __pred is true for each element in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
725 * @p [__first,__last), and false otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
726 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
727 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
728 inline bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
729 all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
730 { return __last == std::find_if_not(__first, __last, __pred); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
731
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
732 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
733 * @brief Checks that a predicate is false for all the elements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
734 * of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
735 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
736 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
737 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
738 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
739 * @return True if the check is true, false otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
740 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
741 * Returns true if @p __pred is false for each element in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
742 * @p [__first,__last), and false otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
743 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
744 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
745 inline bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
746 none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
747 { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
748
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
749 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
750 * @brief Checks that a predicate is false for at least an element
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
751 * of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
752 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
753 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
754 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
755 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
756 * @return True if the check is true, false otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
757 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
758 * Returns true if an element exists in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
759 * [__first,__last) such that @p __pred is true, and false
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
760 * otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
761 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
762 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
763 inline bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
764 any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
765 { return !std::none_of(__first, __last, __pred); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
766
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
767 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
768 * @brief Find the first element in a sequence for which a
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
769 * predicate is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
770 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
771 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
772 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
773 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
774 * @return The first iterator @c i in the range @p [__first,__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
775 * such that @p __pred(*i) is false, or @p __last if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
776 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
777 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
778 inline _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
779 find_if_not(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
780 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
781 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
782 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
783 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
784 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
785 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
786 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
787 return std::__find_if_not(__first, __last, __pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
788 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
789
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
790 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
791 * @brief Checks whether the sequence is partitioned.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
792 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
793 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
794 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
795 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
796 * @return True if the range @p [__first,__last) is partioned by @p __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
797 * i.e. if all elements that satisfy @p __pred appear before those that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
798 * do not.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
799 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
800 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
801 inline bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
802 is_partitioned(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
803 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
804 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
805 __first = std::find_if_not(__first, __last, __pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
806 return std::none_of(__first, __last, __pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
807 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
808
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
809 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
810 * @brief Find the partition point of a partitioned range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
811 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
812 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
813 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
814 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
815 * @return An iterator @p mid such that @p all_of(__first, mid, __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
816 * and @p none_of(mid, __last, __pred) are both true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
817 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
818 template<typename _ForwardIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
819 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
820 partition_point(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
821 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
822 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
823 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
824 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
825 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
826 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
827
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
828 // A specific debug-mode test will be necessary...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
829 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
830
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
831 typedef typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
832 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
833
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
834 _DistanceType __len = std::distance(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
835 _DistanceType __half;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
836 _ForwardIterator __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
837
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
838 while (__len > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
839 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
840 __half = __len >> 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
841 __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
842 std::advance(__middle, __half);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
843 if (__pred(*__middle))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
844 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
845 __first = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
846 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
847 __len = __len - __half - 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
848 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
849 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
850 __len = __half;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
851 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
852 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
853 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
854 #endif
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
855
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
856
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
857 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
858 * @brief Copy a sequence, removing elements of a given value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
859 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
860 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
861 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
862 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
863 * @param __value The value to be removed.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
864 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
865 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
866 * Copies each element in the range @p [__first,__last) not equal
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
867 * to @p __value to the range beginning at @p __result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
868 * remove_copy() is stable, so the relative order of elements that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
869 * are copied is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
870 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
871 template<typename _InputIterator, typename _OutputIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
872 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
873 remove_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
874 _OutputIterator __result, const _Tp& __value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
875 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
876 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
877 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
878 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
879 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
880 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
881 typename iterator_traits<_InputIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
882 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
883
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
884 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
885 if (!(*__first == __value))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
886 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
887 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
888 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
889 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
890 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
891 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
892
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
893 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
894 * @brief Copy a sequence, removing elements for which a predicate is true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
895 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
896 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
897 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
898 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
899 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
900 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
901 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
902 * Copies each element in the range @p [__first,__last) for which
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
903 * @p __pred returns false to the range beginning at @p __result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
904 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
905 * remove_copy_if() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
906 * copied is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
907 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
908 template<typename _InputIterator, typename _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
909 typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
910 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
911 remove_copy_if(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
912 _OutputIterator __result, _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
913 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
914 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
915 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
916 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
917 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
918 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
919 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
920 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
921
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
922 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
923 if (!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
924 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
925 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
926 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
927 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
928 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
929 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
930
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
931 #if __cplusplus >= 201103L
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
932 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
933 * @brief Copy the elements of a sequence for which a predicate is true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
934 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
935 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
936 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
937 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
938 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
939 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
940 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
941 * Copies each element in the range @p [__first,__last) for which
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
942 * @p __pred returns true to the range beginning at @p __result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
943 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
944 * copy_if() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
945 * copied is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
946 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
947 template<typename _InputIterator, typename _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
948 typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
949 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
950 copy_if(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
951 _OutputIterator __result, _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
952 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
953 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
954 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
955 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
956 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
957 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
958 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
959 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
960
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
961 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
962 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
963 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
964 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
965 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
966 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
967 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
968 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
969
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
970
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
971 template<typename _InputIterator, typename _Size, typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
972 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
973 __copy_n(_InputIterator __first, _Size __n,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
974 _OutputIterator __result, input_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
975 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
976 if (__n > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
977 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
978 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
979 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
980 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
981 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
982 if (--__n > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
983 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
984 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
985 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
986 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
987 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
988 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
989 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
990
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
991 template<typename _RandomAccessIterator, typename _Size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
992 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
993 inline _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
994 __copy_n(_RandomAccessIterator __first, _Size __n,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
995 _OutputIterator __result, random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
996 { return std::copy(__first, __first + __n, __result); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
997
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
998 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
999 * @brief Copies the range [first,first+n) into [result,result+n).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1000 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1001 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1002 * @param __n The number of elements to copy.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1003 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1004 * @return result+n.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1005 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1006 * This inline function will boil down to a call to @c memmove whenever
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1007 * possible. Failing that, if random access iterators are passed, then the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1008 * loop count will be known (and therefore a candidate for compiler
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1009 * optimizations such as unrolling).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1010 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1011 template<typename _InputIterator, typename _Size, typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1012 inline _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1013 copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1014 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1015 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1016 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1018 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1019
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1020 return std::__copy_n(__first, __n, __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1021 std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1022 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1023
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1024 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1025 * @brief Copy the elements of a sequence to separate output sequences
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1026 * depending on the truth value of a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1027 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1028 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1029 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1030 * @param __out_true An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1031 * @param __out_false An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1032 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1033 * @return A pair designating the ends of the resulting sequences.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1034 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1035 * Copies each element in the range @p [__first,__last) for which
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1036 * @p __pred returns true to the range beginning at @p out_true
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1037 * and each element for which @p __pred returns false to @p __out_false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1038 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1039 template<typename _InputIterator, typename _OutputIterator1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1040 typename _OutputIterator2, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1041 pair<_OutputIterator1, _OutputIterator2>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1042 partition_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1043 _OutputIterator1 __out_true, _OutputIterator2 __out_false,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1044 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1045 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1046 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1047 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1048 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1049 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1050 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1051 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1052 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1053 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1054 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1055
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1056 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1057 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1058 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1059 *__out_true = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1060 ++__out_true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1061 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1062 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1063 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1064 *__out_false = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1065 ++__out_false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1066 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1067
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1068 return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1069 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1070 #endif
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1071
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1072 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1073 * @brief Remove elements from a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1074 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1075 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1076 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1077 * @param __value The value to be removed.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1078 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1079 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1080 * All elements equal to @p __value are removed from the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1081 * @p [__first,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1082 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1083 * remove() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1084 * not removed is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1085 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1086 * Elements between the end of the resulting sequence and @p __last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1087 * are still present, but their value is unspecified.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1088 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1089 template<typename _ForwardIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1090 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1091 remove(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1092 const _Tp& __value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1093 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1094 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1095 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1096 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1097 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1098 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1099 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1100
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1101 __first = _GLIBCXX_STD_A::find(__first, __last, __value);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1102 if(__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1103 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1104 _ForwardIterator __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1105 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1106 for(; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1107 if(!(*__first == __value))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1108 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1109 *__result = _GLIBCXX_MOVE(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1110 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1111 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1112 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1113 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1114
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1115 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1116 * @brief Remove elements from a sequence using a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1117 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1118 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1119 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1120 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1121 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1122 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1123 * All elements for which @p __pred returns true are removed from the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1124 * @p [__first,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1125 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1126 * remove_if() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1127 * not removed is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1128 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1129 * Elements between the end of the resulting sequence and @p __last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1130 * are still present, but their value is unspecified.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1131 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1132 template<typename _ForwardIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1133 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1134 remove_if(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1135 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1136 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1137 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1138 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1139 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1140 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1141 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1142 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1143
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1144 __first = _GLIBCXX_STD_A::find_if(__first, __last, __pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1145 if(__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1146 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1147 _ForwardIterator __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1148 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1149 for(; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1150 if(!bool(__pred(*__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1151 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1152 *__result = _GLIBCXX_MOVE(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1153 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1154 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1155 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1156 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1157
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1158 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1159 * @brief Remove consecutive duplicate values from a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1160 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1161 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1162 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1163 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1164 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1165 * Removes all but the first element from each group of consecutive
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1166 * values that compare equal.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1167 * unique() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1168 * not removed is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1169 * Elements between the end of the resulting sequence and @p __last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1170 * are still present, but their value is unspecified.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1171 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1172 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1173 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1174 unique(_ForwardIterator __first, _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1175 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1176 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1177 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1178 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1179 __glibcxx_function_requires(_EqualityComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1180 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1181 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1182
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1183 // Skip the beginning, if already unique.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1184 __first = _GLIBCXX_STD_A::adjacent_find(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1185 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1186 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1187
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1188 // Do the real copy work.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1189 _ForwardIterator __dest = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1190 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1191 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1192 if (!(*__dest == *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1193 *++__dest = _GLIBCXX_MOVE(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1194 return ++__dest;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1195 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1196
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1197 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1198 * @brief Remove consecutive values from a sequence using a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1199 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1200 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1201 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1202 * @param __binary_pred A binary predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1203 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1204 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1205 * Removes all but the first element from each group of consecutive
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1206 * values for which @p __binary_pred returns true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1207 * unique() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1208 * not removed is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1209 * Elements between the end of the resulting sequence and @p __last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1210 * are still present, but their value is unspecified.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1211 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1212 template<typename _ForwardIterator, typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1213 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1214 unique(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1215 _BinaryPredicate __binary_pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1216 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1217 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1218 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1219 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1220 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1221 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1222 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1223 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1224
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1225 // Skip the beginning, if already unique.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1226 __first = _GLIBCXX_STD_A::adjacent_find(__first, __last, __binary_pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1227 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1228 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1229
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1230 // Do the real copy work.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1231 _ForwardIterator __dest = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1232 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1233 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1234 if (!bool(__binary_pred(*__dest, *__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1235 *++__dest = _GLIBCXX_MOVE(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1236 return ++__dest;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1237 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1238
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1239 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1240 * This is an uglified unique_copy(_InputIterator, _InputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1241 * _OutputIterator)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1242 * overloaded for forward iterators and output iterator as result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1243 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1244 template<typename _ForwardIterator, typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1245 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1246 __unique_copy(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1247 _OutputIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1248 forward_iterator_tag, output_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1249 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1250 // concept requirements -- taken care of in dispatching function
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1251 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1252 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1253 while (++__next != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1254 if (!(*__first == *__next))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1255 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1256 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1257 *++__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1258 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1259 return ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1260 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1261
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1262 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1263 * This is an uglified unique_copy(_InputIterator, _InputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1264 * _OutputIterator)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1265 * overloaded for input iterators and output iterator as result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1266 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1267 template<typename _InputIterator, typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1268 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1269 __unique_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1270 _OutputIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1271 input_iterator_tag, output_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1272 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1273 // concept requirements -- taken care of in dispatching function
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1274 typename iterator_traits<_InputIterator>::value_type __value = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1275 *__result = __value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1276 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1277 if (!(__value == *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1278 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1279 __value = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1280 *++__result = __value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1281 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1282 return ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1283 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1284
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1285 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1286 * This is an uglified unique_copy(_InputIterator, _InputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1287 * _OutputIterator)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1288 * overloaded for input iterators and forward iterator as result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1289 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1290 template<typename _InputIterator, typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1291 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1292 __unique_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1293 _ForwardIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1294 input_iterator_tag, forward_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1295 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1296 // concept requirements -- taken care of in dispatching function
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1297 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1298 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1299 if (!(*__result == *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1300 *++__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1301 return ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1302 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1303
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1304 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1305 * This is an uglified
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1306 * unique_copy(_InputIterator, _InputIterator, _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1307 * _BinaryPredicate)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1308 * overloaded for forward iterators and output iterator as result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1309 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1310 template<typename _ForwardIterator, typename _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1311 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1312 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1313 __unique_copy(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1314 _OutputIterator __result, _BinaryPredicate __binary_pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1315 forward_iterator_tag, output_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1316 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1317 // concept requirements -- iterators already checked
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1318 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1319 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1320 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1321
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1322 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1323 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1324 while (++__next != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1325 if (!bool(__binary_pred(*__first, *__next)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1326 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1327 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1328 *++__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1329 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1330 return ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1331 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1332
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1333 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1334 * This is an uglified
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1335 * unique_copy(_InputIterator, _InputIterator, _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1336 * _BinaryPredicate)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1337 * overloaded for input iterators and output iterator as result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1338 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1339 template<typename _InputIterator, typename _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1340 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1341 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1342 __unique_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1343 _OutputIterator __result, _BinaryPredicate __binary_pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1344 input_iterator_tag, output_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1345 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1346 // concept requirements -- iterators already checked
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1347 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1348 typename iterator_traits<_InputIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1349 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1350
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1351 typename iterator_traits<_InputIterator>::value_type __value = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1352 *__result = __value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1353 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1354 if (!bool(__binary_pred(__value, *__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1355 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1356 __value = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1357 *++__result = __value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1358 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1359 return ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1360 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1361
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1362 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1363 * This is an uglified
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1364 * unique_copy(_InputIterator, _InputIterator, _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1365 * _BinaryPredicate)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1366 * overloaded for input iterators and forward iterator as result.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1367 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1368 template<typename _InputIterator, typename _ForwardIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1369 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1370 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1371 __unique_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1372 _ForwardIterator __result, _BinaryPredicate __binary_pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1373 input_iterator_tag, forward_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1374 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1375 // concept requirements -- iterators already checked
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1376 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1377 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1378 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1379
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1380 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1381 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1382 if (!bool(__binary_pred(*__result, *__first)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1383 *++__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1384 return ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1385 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1386
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1387 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1388 * This is an uglified reverse(_BidirectionalIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1389 * _BidirectionalIterator)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1390 * overloaded for bidirectional iterators.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1391 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1392 template<typename _BidirectionalIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1393 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1394 __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1395 bidirectional_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1396 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1397 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1398 if (__first == __last || __first == --__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1399 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1400 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1401 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1402 std::iter_swap(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1403 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1404 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1405 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1406
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1407 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1408 * This is an uglified reverse(_BidirectionalIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1409 * _BidirectionalIterator)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1410 * overloaded for random access iterators.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1411 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1412 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1413 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1414 __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1415 random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1416 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1417 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1418 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1419 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1420 while (__first < __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1421 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1422 std::iter_swap(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1423 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1424 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1425 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1426 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1427
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1428 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1429 * @brief Reverse a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1430 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1431 * @param __first A bidirectional iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1432 * @param __last A bidirectional iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1433 * @return reverse() returns no value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1434 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1435 * Reverses the order of the elements in the range @p [__first,__last),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1436 * so that the first element becomes the last etc.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1437 * For every @c i such that @p 0<=i<=(__last-__first)/2), @p reverse()
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1438 * swaps @p *(__first+i) and @p *(__last-(i+1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1439 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1440 template<typename _BidirectionalIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1441 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1442 reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1443 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1444 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1445 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1446 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1447 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1448 std::__reverse(__first, __last, std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1449 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1450
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1451 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1452 * @brief Copy a sequence, reversing its elements.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1453 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1454 * @param __first A bidirectional iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1455 * @param __last A bidirectional iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1456 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1457 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1458 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1459 * Copies the elements in the range @p [__first,__last) to the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1460 * range @p [__result,__result+(__last-__first)) such that the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1461 * order of the elements is reversed. For every @c i such that @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1462 * 0<=i<=(__last-__first), @p reverse_copy() performs the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1463 * assignment @p *(__result+(__last-__first)-1-i) = *(__first+i).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1464 * The ranges @p [__first,__last) and @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1465 * [__result,__result+(__last-__first)) must not overlap.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1466 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1467 template<typename _BidirectionalIterator, typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1468 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1469 reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1470 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1471 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1472 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1473 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1474 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1475 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1476 typename iterator_traits<_BidirectionalIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1477 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1478
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1479 while (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1480 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1481 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1482 *__result = *__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1483 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1484 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1485 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1486 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1487
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1488 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1489 * This is a helper function for the rotate algorithm specialized on RAIs.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1490 * It returns the greatest common divisor of two integer values.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1491 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1492 template<typename _EuclideanRingElement>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1493 _EuclideanRingElement
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1494 __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1495 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1496 while (__n != 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1497 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1498 _EuclideanRingElement __t = __m % __n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1499 __m = __n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1500 __n = __t;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1501 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1502 return __m;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1503 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1504
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1505 /// This is a helper function for the rotate algorithm.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1506 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1507 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1508 __rotate(_ForwardIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1509 _ForwardIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1510 _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1511 forward_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1512 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1513 if (__first == __middle || __last == __middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1514 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1515
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1516 _ForwardIterator __first2 = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1517 do
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1518 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1519 std::iter_swap(__first, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1520 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1521 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1522 if (__first == __middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1523 __middle = __first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1524 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1525 while (__first2 != __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1526
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1527 __first2 = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1528
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1529 while (__first2 != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1530 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1531 std::iter_swap(__first, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1532 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1533 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1534 if (__first == __middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1535 __middle = __first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1536 else if (__first2 == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1537 __first2 = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1538 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1539 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1540
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1541 /// This is a helper function for the rotate algorithm.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1542 template<typename _BidirectionalIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1543 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1544 __rotate(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1545 _BidirectionalIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1546 _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1547 bidirectional_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1548 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1549 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1550 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1551 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1552
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1553 if (__first == __middle || __last == __middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1554 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1555
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1556 std::__reverse(__first, __middle, bidirectional_iterator_tag());
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1557 std::__reverse(__middle, __last, bidirectional_iterator_tag());
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1558
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1559 while (__first != __middle && __middle != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1560 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1561 std::iter_swap(__first, --__last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1562 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1563 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1564
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1565 if (__first == __middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1566 std::__reverse(__middle, __last, bidirectional_iterator_tag());
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1567 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1568 std::__reverse(__first, __middle, bidirectional_iterator_tag());
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1569 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1570
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1571 /// This is a helper function for the rotate algorithm.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1572 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1573 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1574 __rotate(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1575 _RandomAccessIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1576 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1577 random_access_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1578 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1579 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1580 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1581 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1582
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1583 if (__first == __middle || __last == __middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1584 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1585
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1586 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1587 _Distance;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1588 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1589 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1590
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1591 _Distance __n = __last - __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1592 _Distance __k = __middle - __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1593
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1594 if (__k == __n - __k)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1595 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1596 std::swap_ranges(__first, __middle, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1597 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1598 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1599
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1600 _RandomAccessIterator __p = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1601
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1602 for (;;)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1603 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1604 if (__k < __n - __k)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1605 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1606 if (__is_pod(_ValueType) && __k == 1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1607 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1608 _ValueType __t = _GLIBCXX_MOVE(*__p);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1609 _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1610 *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1611 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1612 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1613 _RandomAccessIterator __q = __p + __k;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1614 for (_Distance __i = 0; __i < __n - __k; ++ __i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1615 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1616 std::iter_swap(__p, __q);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1617 ++__p;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1618 ++__q;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1619 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1620 __n %= __k;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1621 if (__n == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1622 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1623 std::swap(__n, __k);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1624 __k = __n - __k;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1625 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1626 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1627 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1628 __k = __n - __k;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1629 if (__is_pod(_ValueType) && __k == 1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1630 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1631 _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1632 _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1633 *__p = _GLIBCXX_MOVE(__t);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1634 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1635 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1636 _RandomAccessIterator __q = __p + __n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1637 __p = __q - __k;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1638 for (_Distance __i = 0; __i < __n - __k; ++ __i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1639 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1640 --__p;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1641 --__q;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1642 std::iter_swap(__p, __q);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1643 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1644 __n %= __k;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1645 if (__n == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1646 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1647 std::swap(__n, __k);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1648 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1649 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1650 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1651
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1652 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1653 * @brief Rotate the elements of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1654 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1655 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1656 * @param __middle A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1657 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1658 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1659 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1660 * Rotates the elements of the range @p [__first,__last) by
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1661 * @p (__middle - __first) positions so that the element at @p __middle
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1662 * is moved to @p __first, the element at @p __middle+1 is moved to
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1663 * @p __first+1 and so on for each element in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1664 * @p [__first,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1665 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1666 * This effectively swaps the ranges @p [__first,__middle) and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1667 * @p [__middle,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1668 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1669 * Performs
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1670 * @p *(__first+(n+(__last-__middle))%(__last-__first))=*(__first+n)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1671 * for each @p n in the range @p [0,__last-__first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1672 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1673 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1674 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1675 rotate(_ForwardIterator __first, _ForwardIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1676 _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1677 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1678 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1679 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1680 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1681 __glibcxx_requires_valid_range(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1682 __glibcxx_requires_valid_range(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1683
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1684 typedef typename iterator_traits<_ForwardIterator>::iterator_category
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1685 _IterType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1686 std::__rotate(__first, __middle, __last, _IterType());
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1687 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1688
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1689 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1690 * @brief Copy a sequence, rotating its elements.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1691 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1692 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1693 * @param __middle A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1694 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1695 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1696 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1697 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1698 * Copies the elements of the range @p [__first,__last) to the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1699 * range beginning at @result, rotating the copied elements by
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1700 * @p (__middle-__first) positions so that the element at @p __middle
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1701 * is moved to @p __result, the element at @p __middle+1 is moved
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1702 * to @p __result+1 and so on for each element in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1703 * [__first,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1704 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1705 * Performs
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1706 * @p *(__result+(n+(__last-__middle))%(__last-__first))=*(__first+n)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1707 * for each @p n in the range @p [0,__last-__first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1708 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1709 template<typename _ForwardIterator, typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1710 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1711 rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1712 _ForwardIterator __last, _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1713 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1714 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1715 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1716 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1717 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1718 __glibcxx_requires_valid_range(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1719 __glibcxx_requires_valid_range(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1720
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1721 return std::copy(__first, __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1722 std::copy(__middle, __last, __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1723 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1724
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1725 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1726 template<typename _ForwardIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1727 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1728 __partition(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1729 _Predicate __pred, forward_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1730 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1731 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1732 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1733
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1734 while (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1735 if (++__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1736 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1737
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1738 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1739
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1740 while (++__next != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1741 if (__pred(*__next))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1742 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1743 std::iter_swap(__first, __next);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1744 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1745 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1746
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1747 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1748 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1749
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1750 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1751 template<typename _BidirectionalIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1752 _BidirectionalIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1753 __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1754 _Predicate __pred, bidirectional_iterator_tag)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1755 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1756 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1757 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1758 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1759 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1760 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1761 else if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1762 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1763 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1764 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1765 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1766 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1767 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1768 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1769 else if (!bool(__pred(*__last)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1770 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1771 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1772 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1773 std::iter_swap(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1774 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1775 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1776 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1777
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1778 // partition
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1779
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1780 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1781 /// Requires __len != 0 and !__pred(*__first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1782 /// same as __stable_partition_adaptive.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1783 template<typename _ForwardIterator, typename _Predicate, typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1784 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1785 __inplace_stable_partition(_ForwardIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1786 _Predicate __pred, _Distance __len)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1787 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1788 if (__len == 1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1789 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1790 _ForwardIterator __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1791 std::advance(__middle, __len / 2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1792 _ForwardIterator __left_split =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1793 std::__inplace_stable_partition(__first, __pred, __len / 2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1794 // Advance past true-predicate values to satisfy this
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1795 // function's preconditions.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1796 _Distance __right_len = __len - __len / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1797 _ForwardIterator __right_split =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1798 std::__find_if_not_n(__middle, __right_len, __pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1799 if (__right_len)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1800 __right_split = std::__inplace_stable_partition(__middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1801 __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1802 __right_len);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1803 std::rotate(__left_split, __middle, __right_split);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1804 std::advance(__left_split, std::distance(__middle, __right_split));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1805 return __left_split;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1806 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1807
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1808 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1809 /// Requires __first != __last and !__pred(*__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1810 /// and __len == distance(__first, __last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1811 ///
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1812 /// !__pred(*__first) allows us to guarantee that we don't
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1813 /// move-assign an element onto itself.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1814 template<typename _ForwardIterator, typename _Pointer, typename _Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1815 typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1816 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1817 __stable_partition_adaptive(_ForwardIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1818 _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1819 _Predicate __pred, _Distance __len,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1820 _Pointer __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1821 _Distance __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1822 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1823 if (__len <= __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1824 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1825 _ForwardIterator __result1 = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1826 _Pointer __result2 = __buffer;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1827 // The precondition guarantees that !__pred(*__first), so
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1828 // move that element to the buffer before starting the loop.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1829 // This ensures that we only call __pred once per element.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1830 *__result2 = _GLIBCXX_MOVE(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1831 ++__result2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1832 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1833 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1834 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1835 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1836 *__result1 = _GLIBCXX_MOVE(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1837 ++__result1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1838 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1839 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1840 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1841 *__result2 = _GLIBCXX_MOVE(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1842 ++__result2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1843 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1844 _GLIBCXX_MOVE3(__buffer, __result2, __result1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1845 return __result1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1846 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1847 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1848 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1849 _ForwardIterator __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1850 std::advance(__middle, __len / 2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1851 _ForwardIterator __left_split =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1852 std::__stable_partition_adaptive(__first, __middle, __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1853 __len / 2, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1854 __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1855 // Advance past true-predicate values to satisfy this
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1856 // function's preconditions.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1857 _Distance __right_len = __len - __len / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1858 _ForwardIterator __right_split =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1859 std::__find_if_not_n(__middle, __right_len, __pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1860 if (__right_len)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1861 __right_split =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1862 std::__stable_partition_adaptive(__right_split, __last, __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1863 __right_len,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1864 __buffer, __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1865 std::rotate(__left_split, __middle, __right_split);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1866 std::advance(__left_split, std::distance(__middle, __right_split));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1867 return __left_split;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1868 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1869 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1870
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1871 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1872 * @brief Move elements for which a predicate is true to the beginning
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1873 * of a sequence, preserving relative ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1874 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1875 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1876 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1877 * @param __pred A predicate functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1878 * @return An iterator @p middle such that @p __pred(i) is true for each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1879 * iterator @p i in the range @p [first,middle) and false for each @p i
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1880 * in the range @p [middle,last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1881 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1882 * Performs the same function as @p partition() with the additional
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1883 * guarantee that the relative ordering of elements in each group is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1884 * preserved, so any two elements @p x and @p y in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1885 * @p [__first,__last) such that @p __pred(x)==__pred(y) will have the same
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1886 * relative ordering after calling @p stable_partition().
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1887 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1888 template<typename _ForwardIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1889 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1890 stable_partition(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1891 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1892 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1893 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1894 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1895 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1896 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1897 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1898 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1899
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1900 __first = std::__find_if_not(__first, __last, __pred);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1901
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1902 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1903 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1904 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1905 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1906 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1907 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1908 typedef typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1909 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1910
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1911 _Temporary_buffer<_ForwardIterator, _ValueType> __buf(__first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1912 __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1913 if (__buf.size() > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1914 return
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1915 std::__stable_partition_adaptive(__first, __last, __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1916 _DistanceType(__buf.requested_size()),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1917 __buf.begin(),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1918 _DistanceType(__buf.size()));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1919 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1920 return
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1921 std::__inplace_stable_partition(__first, __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1922 _DistanceType(__buf.requested_size()));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1923 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1924 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1925
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1926 /// This is a helper function for the sort routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1927 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1928 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1929 __heap_select(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1930 _RandomAccessIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1931 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1932 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1933 std::make_heap(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1934 for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1935 if (*__i < *__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1936 std::__pop_heap(__first, __middle, __i);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1937 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1938
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1939 /// This is a helper function for the sort routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1940 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1941 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1942 __heap_select(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1943 _RandomAccessIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1944 _RandomAccessIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1945 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1946 std::make_heap(__first, __middle, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1947 for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1948 if (__comp(*__i, *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1949 std::__pop_heap(__first, __middle, __i, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1950 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1951
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1952 // partial_sort
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1953
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1954 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1955 * @brief Copy the smallest elements of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1956 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1957 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1958 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1959 * @param __result_first A random-access iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1960 * @param __result_last Another random-access iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1961 * @return An iterator indicating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1962 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1963 * Copies and sorts the smallest N values from the range @p [__first,__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1964 * to the range beginning at @p __result_first, where the number of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1965 * elements to be copied, @p N, is the smaller of @p (__last-__first) and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1966 * @p (__result_last-__result_first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1967 * After the sort if @e i and @e j are iterators in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1968 * @p [__result_first,__result_first+N) such that i precedes j then
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1969 * *j<*i is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1970 * The value returned is @p __result_first+N.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1971 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1972 template<typename _InputIterator, typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1973 _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1974 partial_sort_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1975 _RandomAccessIterator __result_first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1976 _RandomAccessIterator __result_last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1977 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1978 typedef typename iterator_traits<_InputIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1979 _InputValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1980 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1981 _OutputValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1982 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1983 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1984
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1985 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1986 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1987 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1988 _OutputValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1989 __glibcxx_function_requires(_LessThanOpConcept<_InputValueType,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1990 _OutputValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1991 __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1992 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1993 __glibcxx_requires_valid_range(__result_first, __result_last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1994
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1995 if (__result_first == __result_last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1996 return __result_last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1997 _RandomAccessIterator __result_real_last = __result_first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1998 while(__first != __last && __result_real_last != __result_last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1999 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2000 *__result_real_last = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2001 ++__result_real_last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2002 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2003 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2004 std::make_heap(__result_first, __result_real_last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2005 while (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2006 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2007 if (*__first < *__result_first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2008 std::__adjust_heap(__result_first, _DistanceType(0),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2009 _DistanceType(__result_real_last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2010 - __result_first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2011 _InputValueType(*__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2012 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2013 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2014 std::sort_heap(__result_first, __result_real_last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2015 return __result_real_last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2016 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2017
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2018 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2019 * @brief Copy the smallest elements of a sequence using a predicate for
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2020 * comparison.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2021 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2022 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2023 * @param __last Another input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2024 * @param __result_first A random-access iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2025 * @param __result_last Another random-access iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2026 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2027 * @return An iterator indicating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2028 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2029 * Copies and sorts the smallest N values from the range @p [__first,__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2030 * to the range beginning at @p result_first, where the number of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2031 * elements to be copied, @p N, is the smaller of @p (__last-__first) and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2032 * @p (__result_last-__result_first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2033 * After the sort if @e i and @e j are iterators in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2034 * @p [__result_first,__result_first+N) such that i precedes j then
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2035 * @p __comp(*j,*i) is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2036 * The value returned is @p __result_first+N.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2037 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2038 template<typename _InputIterator, typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2039 _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2040 partial_sort_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2041 _RandomAccessIterator __result_first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2042 _RandomAccessIterator __result_last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2043 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2044 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2045 typedef typename iterator_traits<_InputIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2046 _InputValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2047 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2048 _OutputValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2049 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2050 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2051
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2052 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2053 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2054 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2055 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2056 __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2057 _OutputValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2058 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2059 _InputValueType, _OutputValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2060 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2061 _OutputValueType, _OutputValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2062 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2063 __glibcxx_requires_valid_range(__result_first, __result_last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2064
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2065 if (__result_first == __result_last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2066 return __result_last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2067 _RandomAccessIterator __result_real_last = __result_first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2068 while(__first != __last && __result_real_last != __result_last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2069 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2070 *__result_real_last = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2071 ++__result_real_last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2072 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2073 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2074 std::make_heap(__result_first, __result_real_last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2075 while (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2076 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2077 if (__comp(*__first, *__result_first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2078 std::__adjust_heap(__result_first, _DistanceType(0),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2079 _DistanceType(__result_real_last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2080 - __result_first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2081 _InputValueType(*__first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2082 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2083 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2084 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2085 std::sort_heap(__result_first, __result_real_last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2086 return __result_real_last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2087 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2088
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2089 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2090 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2091 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2092 __unguarded_linear_insert(_RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2093 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2094 typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2095 __val = _GLIBCXX_MOVE(*__last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2096 _RandomAccessIterator __next = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2097 --__next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2098 while (__val < *__next)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2099 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2100 *__last = _GLIBCXX_MOVE(*__next);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2101 __last = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2102 --__next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2103 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2104 *__last = _GLIBCXX_MOVE(__val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2105 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2106
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2107 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2108 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2109 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2110 __unguarded_linear_insert(_RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2111 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2112 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2113 typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2114 __val = _GLIBCXX_MOVE(*__last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2115 _RandomAccessIterator __next = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2116 --__next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2117 while (__comp(__val, *__next))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2118 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2119 *__last = _GLIBCXX_MOVE(*__next);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2120 __last = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2121 --__next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2122 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2123 *__last = _GLIBCXX_MOVE(__val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2124 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2125
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2126 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2127 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2128 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2129 __insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2130 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2131 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2132 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2133 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2134
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2135 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2136 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2137 if (*__i < *__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2138 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2139 typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2140 __val = _GLIBCXX_MOVE(*__i);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2141 _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2142 *__first = _GLIBCXX_MOVE(__val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2143 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2144 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2145 std::__unguarded_linear_insert(__i);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2146 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2147 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2148
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2149 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2150 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2151 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2152 __insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2153 _RandomAccessIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2154 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2155 if (__first == __last) return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2156
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2157 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2158 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2159 if (__comp(*__i, *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2160 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2161 typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2162 __val = _GLIBCXX_MOVE(*__i);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2163 _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2164 *__first = _GLIBCXX_MOVE(__val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2165 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2166 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2167 std::__unguarded_linear_insert(__i, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2168 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2169 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2170
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2171 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2172 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2173 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2174 __unguarded_insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2175 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2176 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2177 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2178 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2179
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2180 for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2181 std::__unguarded_linear_insert(__i);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2182 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2183
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2184 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2185 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2186 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2187 __unguarded_insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2188 _RandomAccessIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2189 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2190 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2191 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2192
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2193 for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2194 std::__unguarded_linear_insert(__i, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2195 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2196
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2197 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2198 * @doctodo
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2199 * This controls some aspect of the sort routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2200 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2201 enum { _S_threshold = 16 };
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2202
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2203 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2204 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2205 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2206 __final_insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2207 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2208 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2209 if (__last - __first > int(_S_threshold))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2210 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2211 std::__insertion_sort(__first, __first + int(_S_threshold));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2212 std::__unguarded_insertion_sort(__first + int(_S_threshold), __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2213 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2214 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2215 std::__insertion_sort(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2216 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2217
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2218 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2219 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2220 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2221 __final_insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2222 _RandomAccessIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2223 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2224 if (__last - __first > int(_S_threshold))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2225 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2226 std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2227 std::__unguarded_insertion_sort(__first + int(_S_threshold), __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2228 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2229 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2230 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2231 std::__insertion_sort(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2232 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2233
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2234 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2235 template<typename _RandomAccessIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2236 _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2237 __unguarded_partition(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2238 _RandomAccessIterator __last, const _Tp& __pivot)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2239 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2240 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2241 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2242 while (*__first < __pivot)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2243 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2244 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2245 while (__pivot < *__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2246 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2247 if (!(__first < __last))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2248 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2249 std::iter_swap(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2250 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2251 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2252 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2253
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2254 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2255 template<typename _RandomAccessIterator, typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2256 _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2257 __unguarded_partition(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2258 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2259 const _Tp& __pivot, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2260 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2261 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2262 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2263 while (__comp(*__first, __pivot))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2264 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2265 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2266 while (__comp(__pivot, *__last))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2267 --__last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2268 if (!(__first < __last))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2269 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2270 std::iter_swap(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2271 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2272 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2273 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2274
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2275 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2276 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2277 inline _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2278 __unguarded_partition_pivot(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2279 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2280 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2281 _RandomAccessIterator __mid = __first + (__last - __first) / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2282 std::__move_median_to_first(__first, __first + 1, __mid, __last - 1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2283 return std::__unguarded_partition(__first + 1, __last, *__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2284 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2285
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2286
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2287 /// This is a helper function...
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2288 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2289 inline _RandomAccessIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2290 __unguarded_partition_pivot(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2291 _RandomAccessIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2292 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2293 _RandomAccessIterator __mid = __first + (__last - __first) / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2294 std::__move_median_to_first(__first, __first + 1, __mid, __last - 1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2295 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2296 return std::__unguarded_partition(__first + 1, __last, *__first, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2297 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2298
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2299 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2300 template<typename _RandomAccessIterator, typename _Size>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2301 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2302 __introsort_loop(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2303 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2304 _Size __depth_limit)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2305 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2306 while (__last - __first > int(_S_threshold))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2307 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2308 if (__depth_limit == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2309 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2310 _GLIBCXX_STD_A::partial_sort(__first, __last, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2311 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2312 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2313 --__depth_limit;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2314 _RandomAccessIterator __cut =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2315 std::__unguarded_partition_pivot(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2316 std::__introsort_loop(__cut, __last, __depth_limit);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2317 __last = __cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2318 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2319 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2320
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2321 /// This is a helper function for the sort routine.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2322 template<typename _RandomAccessIterator, typename _Size, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2323 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2324 __introsort_loop(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2325 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2326 _Size __depth_limit, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2327 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2328 while (__last - __first > int(_S_threshold))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2329 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2330 if (__depth_limit == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2331 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2332 _GLIBCXX_STD_A::partial_sort(__first, __last, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2333 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2334 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2335 --__depth_limit;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2336 _RandomAccessIterator __cut =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2337 std::__unguarded_partition_pivot(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2338 std::__introsort_loop(__cut, __last, __depth_limit, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2339 __last = __cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2340 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2341 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2342
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2343 // sort
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2344
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2345 template<typename _RandomAccessIterator, typename _Size>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2346 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2347 __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2348 _RandomAccessIterator __last, _Size __depth_limit)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2349 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2350 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2351 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2352
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2353 while (__last - __first > 3)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2354 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2355 if (__depth_limit == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2356 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2357 std::__heap_select(__first, __nth + 1, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2358
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2359 // Place the nth largest element in its final position.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2360 std::iter_swap(__first, __nth);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2361 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2362 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2363 --__depth_limit;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2364 _RandomAccessIterator __cut =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2365 std::__unguarded_partition_pivot(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2366 if (__cut <= __nth)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2367 __first = __cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2368 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2369 __last = __cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2370 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2371 std::__insertion_sort(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2372 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2373
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2374 template<typename _RandomAccessIterator, typename _Size, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2375 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2376 __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2377 _RandomAccessIterator __last, _Size __depth_limit,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2378 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2379 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2380 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2381 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2382
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2383 while (__last - __first > 3)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2384 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2385 if (__depth_limit == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2386 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2387 std::__heap_select(__first, __nth + 1, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2388 // Place the nth largest element in its final position.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2389 std::iter_swap(__first, __nth);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2390 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2391 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2392 --__depth_limit;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2393 _RandomAccessIterator __cut =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2394 std::__unguarded_partition_pivot(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2395 if (__cut <= __nth)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2396 __first = __cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2397 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2398 __last = __cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2399 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2400 std::__insertion_sort(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2401 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2402
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2403 // nth_element
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2404
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2405 // lower_bound moved to stl_algobase.h
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2406
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2407 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2408 * @brief Finds the first position in which @p __val could be inserted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2409 * without changing the ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2410 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2411 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2412 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2413 * @param __val The search term.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2414 * @param __comp A functor to use for comparisons.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2415 * @return An iterator pointing to the first element <em>not less
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2416 * than</em> @p __val, or end() if every element is less
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2417 * than @p __val.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2418 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2419 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2420 * The comparison function should have the same effects on ordering as
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2421 * the function used for the initial sort.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2422 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2423 template<typename _ForwardIterator, typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2424 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2425 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2426 const _Tp& __val, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2427 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2428 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2429 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2430 typedef typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2431 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2432
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2433 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2434 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2435 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2436 _ValueType, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2437 __glibcxx_requires_partitioned_lower_pred(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2438 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2439
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2440 _DistanceType __len = std::distance(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2441
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2442 while (__len > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2443 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2444 _DistanceType __half = __len >> 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2445 _ForwardIterator __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2446 std::advance(__middle, __half);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2447 if (__comp(*__middle, __val))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2448 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2449 __first = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2450 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2451 __len = __len - __half - 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2452 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2453 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2454 __len = __half;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2455 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2456 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2457 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2458
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2459 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2460 * @brief Finds the last position in which @p __val could be inserted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2461 * without changing the ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2462 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2463 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2464 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2465 * @param __val The search term.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2466 * @return An iterator pointing to the first element greater than @p __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2467 * or end() if no elements are greater than @p __val.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2468 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2469 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2470 template<typename _ForwardIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2471 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2472 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2473 const _Tp& __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2474 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2475 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2476 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2477 typedef typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2478 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2479
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2480 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2481 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2482 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2483 __glibcxx_requires_partitioned_upper(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2484
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2485 _DistanceType __len = std::distance(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2486
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2487 while (__len > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2488 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2489 _DistanceType __half = __len >> 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2490 _ForwardIterator __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2491 std::advance(__middle, __half);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2492 if (__val < *__middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2493 __len = __half;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2494 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2495 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2496 __first = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2497 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2498 __len = __len - __half - 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2499 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2500 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2501 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2502 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2503
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2504 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2505 * @brief Finds the last position in which @p __val could be inserted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2506 * without changing the ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2507 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2508 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2509 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2510 * @param __val The search term.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2511 * @param __comp A functor to use for comparisons.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2512 * @return An iterator pointing to the first element greater than @p __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2513 * or end() if no elements are greater than @p __val.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2514 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2515 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2516 * The comparison function should have the same effects on ordering as
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2517 * the function used for the initial sort.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2518 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2519 template<typename _ForwardIterator, typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2520 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2521 upper_bound(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2522 const _Tp& __val, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2523 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2524 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2525 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2526 typedef typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2527 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2528
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2529 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2530 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2531 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2532 _Tp, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2533 __glibcxx_requires_partitioned_upper_pred(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2534 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2535
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2536 _DistanceType __len = std::distance(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2537
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2538 while (__len > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2539 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2540 _DistanceType __half = __len >> 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2541 _ForwardIterator __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2542 std::advance(__middle, __half);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2543 if (__comp(__val, *__middle))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2544 __len = __half;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2545 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2546 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2547 __first = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2548 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2549 __len = __len - __half - 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2550 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2551 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2552 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2553 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2554
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2555 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2556 * @brief Finds the largest subrange in which @p __val could be inserted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2557 * at any place in it without changing the ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2558 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2559 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2560 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2561 * @param __val The search term.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2562 * @return An pair of iterators defining the subrange.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2563 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2564 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2565 * This is equivalent to
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2566 * @code
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2567 * std::make_pair(lower_bound(__first, __last, __val),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2568 * upper_bound(__first, __last, __val))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2569 * @endcode
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2570 * but does not actually call those functions.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2571 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2572 template<typename _ForwardIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2573 pair<_ForwardIterator, _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2574 equal_range(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2575 const _Tp& __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2576 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2577 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2578 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2579 typedef typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2580 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2581
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2582 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2583 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2584 __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2585 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2586 __glibcxx_requires_partitioned_lower(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2587 __glibcxx_requires_partitioned_upper(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2588
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2589 _DistanceType __len = std::distance(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2590
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2591 while (__len > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2592 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2593 _DistanceType __half = __len >> 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2594 _ForwardIterator __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2595 std::advance(__middle, __half);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2596 if (*__middle < __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2597 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2598 __first = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2599 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2600 __len = __len - __half - 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2601 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2602 else if (__val < *__middle)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2603 __len = __half;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2604 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2605 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2606 _ForwardIterator __left = std::lower_bound(__first, __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2607 __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2608 std::advance(__first, __len);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2609 _ForwardIterator __right = std::upper_bound(++__middle, __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2610 __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2611 return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2612 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2613 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2614 return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2615 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2616
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2617 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2618 * @brief Finds the largest subrange in which @p __val could be inserted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2619 * at any place in it without changing the ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2620 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2621 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2622 * @param __val The search term.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2623 * @param __comp A functor to use for comparisons.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2624 * @return An pair of iterators defining the subrange.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2625 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2626 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2627 * This is equivalent to
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2628 * @code
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2629 * std::make_pair(lower_bound(__first, __last, __val, __comp),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2630 * upper_bound(__first, __last, __val, __comp))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2631 * @endcode
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2632 * but does not actually call those functions.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2633 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2634 template<typename _ForwardIterator, typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2635 pair<_ForwardIterator, _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2636 equal_range(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2637 const _Tp& __val, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2638 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2639 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2640 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2641 typedef typename iterator_traits<_ForwardIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2642 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2643
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2644 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2645 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2646 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2647 _ValueType, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2648 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2649 _Tp, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2650 __glibcxx_requires_partitioned_lower_pred(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2651 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2652 __glibcxx_requires_partitioned_upper_pred(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2653 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2654
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2655 _DistanceType __len = std::distance(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2656
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2657 while (__len > 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2658 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2659 _DistanceType __half = __len >> 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2660 _ForwardIterator __middle = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2661 std::advance(__middle, __half);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2662 if (__comp(*__middle, __val))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2663 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2664 __first = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2665 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2666 __len = __len - __half - 1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2667 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2668 else if (__comp(__val, *__middle))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2669 __len = __half;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2670 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2671 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2672 _ForwardIterator __left = std::lower_bound(__first, __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2673 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2674 std::advance(__first, __len);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2675 _ForwardIterator __right = std::upper_bound(++__middle, __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2676 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2677 return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2678 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2679 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2680 return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2681 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2682
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2683 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2684 * @brief Determines whether an element exists in a range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2685 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2686 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2687 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2688 * @param __val The search term.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2689 * @return True if @p __val (or its equivalent) is in [@p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2690 * __first,@p __last ].
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2691 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2692 * Note that this does not actually return an iterator to @p __val. For
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2693 * that, use std::find or a container's specialized find member functions.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2694 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2695 template<typename _ForwardIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2696 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2697 binary_search(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2698 const _Tp& __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2699 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2700 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2701 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2702
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2703 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2704 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2705 __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2706 __glibcxx_requires_partitioned_lower(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2707 __glibcxx_requires_partitioned_upper(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2708
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2709 _ForwardIterator __i = std::lower_bound(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2710 return __i != __last && !(__val < *__i);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2711 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2712
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2713 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2714 * @brief Determines whether an element exists in a range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2715 * @ingroup binary_search_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2716 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2717 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2718 * @param __val The search term.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2719 * @param __comp A functor to use for comparisons.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2720 * @return True if @p __val (or its equivalent) is in @p [__first,__last].
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2721 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2722 * Note that this does not actually return an iterator to @p __val. For
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2723 * that, use std::find or a container's specialized find member functions.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2724 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2725 * The comparison function should have the same effects on ordering as
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2726 * the function used for the initial sort.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2727 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2728 template<typename _ForwardIterator, typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2729 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2730 binary_search(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2731 const _Tp& __val, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2732 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2733 typedef typename iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2734 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2735
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2736 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2737 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2738 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2739 _Tp, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2740 __glibcxx_requires_partitioned_lower_pred(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2741 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2742 __glibcxx_requires_partitioned_upper_pred(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2743 __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2744
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2745 _ForwardIterator __i = std::lower_bound(__first, __last, __val, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2746 return __i != __last && !bool(__comp(__val, *__i));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2747 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2748
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2749 // merge
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2750
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2751 /// This is a helper function for the __merge_adaptive routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2752 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2753 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2754 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2755 __move_merge_adaptive(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2756 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2757 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2758 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2759 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2760 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2761 if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2762 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2763 *__result = _GLIBCXX_MOVE(*__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2764 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2765 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2766 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2767 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2768 *__result = _GLIBCXX_MOVE(*__first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2769 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2770 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2771 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2772 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2773 if (__first1 != __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2774 _GLIBCXX_MOVE3(__first1, __last1, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2775 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2776
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2777 /// This is a helper function for the __merge_adaptive routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2778 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2779 typename _OutputIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2780 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2781 __move_merge_adaptive(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2782 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2783 _OutputIterator __result, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2784 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2785 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2786 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2787 if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2788 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2789 *__result = _GLIBCXX_MOVE(*__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2790 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2791 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2792 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2793 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2794 *__result = _GLIBCXX_MOVE(*__first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2795 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2796 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2797 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2798 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2799 if (__first1 != __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2800 _GLIBCXX_MOVE3(__first1, __last1, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2801 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2802
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2803 /// This is a helper function for the __merge_adaptive routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2804 template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2805 typename _BidirectionalIterator3>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2806 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2807 __move_merge_adaptive_backward(_BidirectionalIterator1 __first1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2808 _BidirectionalIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2809 _BidirectionalIterator2 __first2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2810 _BidirectionalIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2811 _BidirectionalIterator3 __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2812 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2813 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2814 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2815 _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2816 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2817 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2818 else if (__first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2819 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2820
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2821 --__last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2822 --__last2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2823 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2824 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2825 if (*__last2 < *__last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2826 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2827 *--__result = _GLIBCXX_MOVE(*__last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2828 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2829 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2830 _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2831 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2832 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2833 --__last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2834 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2835 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2836 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2837 *--__result = _GLIBCXX_MOVE(*__last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2838 if (__first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2839 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2840 --__last2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2841 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2842 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2843 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2844
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2845 /// This is a helper function for the __merge_adaptive routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2846 template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2847 typename _BidirectionalIterator3, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2848 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2849 __move_merge_adaptive_backward(_BidirectionalIterator1 __first1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2850 _BidirectionalIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2851 _BidirectionalIterator2 __first2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2852 _BidirectionalIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2853 _BidirectionalIterator3 __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2854 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2855 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2856 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2857 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2858 _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2859 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2860 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2861 else if (__first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2862 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2863
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2864 --__last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2865 --__last2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2866 while (true)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2867 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2868 if (__comp(*__last2, *__last1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2869 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2870 *--__result = _GLIBCXX_MOVE(*__last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2871 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2872 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2873 _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2874 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2875 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2876 --__last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2877 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2878 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2879 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2880 *--__result = _GLIBCXX_MOVE(*__last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2881 if (__first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2882 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2883 --__last2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2884 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2885 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2886 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2887
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2888 /// This is a helper function for the merge routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2889 template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2890 typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2891 _BidirectionalIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2892 __rotate_adaptive(_BidirectionalIterator1 __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2893 _BidirectionalIterator1 __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2894 _BidirectionalIterator1 __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2895 _Distance __len1, _Distance __len2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2896 _BidirectionalIterator2 __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2897 _Distance __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2898 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2899 _BidirectionalIterator2 __buffer_end;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2900 if (__len1 > __len2 && __len2 <= __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2901 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2902 if (__len2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2903 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2904 __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2905 _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2906 return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2907 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2908 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2909 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2910 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2911 else if (__len1 <= __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2912 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2913 if (__len1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2914 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2915 __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2916 _GLIBCXX_MOVE3(__middle, __last, __first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2917 return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2918 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2919 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2920 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2921 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2922 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2923 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2924 std::rotate(__first, __middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2925 std::advance(__first, std::distance(__middle, __last));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2926 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2927 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2928 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2929
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2930 /// This is a helper function for the merge routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2931 template<typename _BidirectionalIterator, typename _Distance,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2932 typename _Pointer>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2933 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2934 __merge_adaptive(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2935 _BidirectionalIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2936 _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2937 _Distance __len1, _Distance __len2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2938 _Pointer __buffer, _Distance __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2939 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2940 if (__len1 <= __len2 && __len1 <= __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2941 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2942 _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2943 std::__move_merge_adaptive(__buffer, __buffer_end, __middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2944 __first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2945 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2946 else if (__len2 <= __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2947 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2948 _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2949 std::__move_merge_adaptive_backward(__first, __middle, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2950 __buffer_end, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2951 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2952 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2953 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2954 _BidirectionalIterator __first_cut = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2955 _BidirectionalIterator __second_cut = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2956 _Distance __len11 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2957 _Distance __len22 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2958 if (__len1 > __len2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2959 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2960 __len11 = __len1 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2961 std::advance(__first_cut, __len11);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2962 __second_cut = std::lower_bound(__middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2963 *__first_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2964 __len22 = std::distance(__middle, __second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2965 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2966 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2967 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2968 __len22 = __len2 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2969 std::advance(__second_cut, __len22);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2970 __first_cut = std::upper_bound(__first, __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2971 *__second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2972 __len11 = std::distance(__first, __first_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2973 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2974 _BidirectionalIterator __new_middle =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2975 std::__rotate_adaptive(__first_cut, __middle, __second_cut,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2976 __len1 - __len11, __len22, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2977 __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2978 std::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2979 __len22, __buffer, __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2980 std::__merge_adaptive(__new_middle, __second_cut, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2981 __len1 - __len11,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2982 __len2 - __len22, __buffer, __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2983 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2984 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2985
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2986 /// This is a helper function for the merge routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2987 template<typename _BidirectionalIterator, typename _Distance,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2988 typename _Pointer, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2989 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2990 __merge_adaptive(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2991 _BidirectionalIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2992 _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2993 _Distance __len1, _Distance __len2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2994 _Pointer __buffer, _Distance __buffer_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2995 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2996 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2997 if (__len1 <= __len2 && __len1 <= __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2998 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2999 _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3000 std::__move_merge_adaptive(__buffer, __buffer_end, __middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3001 __first, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3002 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3003 else if (__len2 <= __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3004 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3005 _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3006 std::__move_merge_adaptive_backward(__first, __middle, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3007 __buffer_end, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3008 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3009 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3010 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3011 _BidirectionalIterator __first_cut = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3012 _BidirectionalIterator __second_cut = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3013 _Distance __len11 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3014 _Distance __len22 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3015 if (__len1 > __len2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3016 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3017 __len11 = __len1 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3018 std::advance(__first_cut, __len11);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3019 __second_cut = std::lower_bound(__middle, __last, *__first_cut,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3020 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3021 __len22 = std::distance(__middle, __second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3022 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3023 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3024 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3025 __len22 = __len2 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3026 std::advance(__second_cut, __len22);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3027 __first_cut = std::upper_bound(__first, __middle, *__second_cut,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3028 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3029 __len11 = std::distance(__first, __first_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3030 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3031 _BidirectionalIterator __new_middle =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3032 std::__rotate_adaptive(__first_cut, __middle, __second_cut,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3033 __len1 - __len11, __len22, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3034 __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3035 std::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3036 __len22, __buffer, __buffer_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3037 std::__merge_adaptive(__new_middle, __second_cut, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3038 __len1 - __len11,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3039 __len2 - __len22, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3040 __buffer_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3041 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3042 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3043
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3044 /// This is a helper function for the merge routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3045 template<typename _BidirectionalIterator, typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3046 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3047 __merge_without_buffer(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3048 _BidirectionalIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3049 _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3050 _Distance __len1, _Distance __len2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3051 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3052 if (__len1 == 0 || __len2 == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3053 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3054 if (__len1 + __len2 == 2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3055 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3056 if (*__middle < *__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3057 std::iter_swap(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3058 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3059 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3060 _BidirectionalIterator __first_cut = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3061 _BidirectionalIterator __second_cut = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3062 _Distance __len11 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3063 _Distance __len22 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3064 if (__len1 > __len2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3065 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3066 __len11 = __len1 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3067 std::advance(__first_cut, __len11);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3068 __second_cut = std::lower_bound(__middle, __last, *__first_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3069 __len22 = std::distance(__middle, __second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3070 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3071 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3072 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3073 __len22 = __len2 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3074 std::advance(__second_cut, __len22);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3075 __first_cut = std::upper_bound(__first, __middle, *__second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3076 __len11 = std::distance(__first, __first_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3077 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3078 std::rotate(__first_cut, __middle, __second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3079 _BidirectionalIterator __new_middle = __first_cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3080 std::advance(__new_middle, std::distance(__middle, __second_cut));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3081 std::__merge_without_buffer(__first, __first_cut, __new_middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3082 __len11, __len22);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3083 std::__merge_without_buffer(__new_middle, __second_cut, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3084 __len1 - __len11, __len2 - __len22);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3085 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3086
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3087 /// This is a helper function for the merge routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3088 template<typename _BidirectionalIterator, typename _Distance,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3089 typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3090 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3091 __merge_without_buffer(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3092 _BidirectionalIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3093 _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3094 _Distance __len1, _Distance __len2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3095 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3096 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3097 if (__len1 == 0 || __len2 == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3098 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3099 if (__len1 + __len2 == 2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3100 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3101 if (__comp(*__middle, *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3102 std::iter_swap(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3103 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3104 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3105 _BidirectionalIterator __first_cut = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3106 _BidirectionalIterator __second_cut = __middle;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3107 _Distance __len11 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3108 _Distance __len22 = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3109 if (__len1 > __len2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3110 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3111 __len11 = __len1 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3112 std::advance(__first_cut, __len11);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3113 __second_cut = std::lower_bound(__middle, __last, *__first_cut,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3114 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3115 __len22 = std::distance(__middle, __second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3116 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3117 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3118 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3119 __len22 = __len2 / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3120 std::advance(__second_cut, __len22);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3121 __first_cut = std::upper_bound(__first, __middle, *__second_cut,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3122 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3123 __len11 = std::distance(__first, __first_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3124 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3125 std::rotate(__first_cut, __middle, __second_cut);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3126 _BidirectionalIterator __new_middle = __first_cut;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3127 std::advance(__new_middle, std::distance(__middle, __second_cut));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3128 std::__merge_without_buffer(__first, __first_cut, __new_middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3129 __len11, __len22, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3130 std::__merge_without_buffer(__new_middle, __second_cut, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3131 __len1 - __len11, __len2 - __len22, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3132 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3133
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3134 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3135 * @brief Merges two sorted ranges in place.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3136 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3137 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3138 * @param __middle Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3139 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3140 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3141 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3142 * Merges two sorted and consecutive ranges, [__first,__middle) and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3143 * [__middle,__last), and puts the result in [__first,__last). The
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3144 * output will be sorted. The sort is @e stable, that is, for
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3145 * equivalent elements in the two ranges, elements from the first
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3146 * range will always come before elements from the second.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3147 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3148 * If enough additional memory is available, this takes (__last-__first)-1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3149 * comparisons. Otherwise an NlogN algorithm is used, where N is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3150 * distance(__first,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3151 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3152 template<typename _BidirectionalIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3153 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3154 inplace_merge(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3155 _BidirectionalIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3156 _BidirectionalIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3157 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3158 typedef typename iterator_traits<_BidirectionalIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3159 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3160 typedef typename iterator_traits<_BidirectionalIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3161 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3162
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3163 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3164 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3165 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3166 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3167 __glibcxx_requires_sorted(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3168 __glibcxx_requires_sorted(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3169
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3170 if (__first == __middle || __middle == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3171 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3172
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3173 _DistanceType __len1 = std::distance(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3174 _DistanceType __len2 = std::distance(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3175
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3176 _Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3177 __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3178 if (__buf.begin() == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3179 std::__merge_without_buffer(__first, __middle, __last, __len1, __len2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3180 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3181 std::__merge_adaptive(__first, __middle, __last, __len1, __len2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3182 __buf.begin(), _DistanceType(__buf.size()));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3183 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3184
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3185 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3186 * @brief Merges two sorted ranges in place.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3187 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3188 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3189 * @param __middle Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3190 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3191 * @param __comp A functor to use for comparisons.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3192 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3193 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3194 * Merges two sorted and consecutive ranges, [__first,__middle) and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3195 * [middle,last), and puts the result in [__first,__last). The output will
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3196 * be sorted. The sort is @e stable, that is, for equivalent
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3197 * elements in the two ranges, elements from the first range will always
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3198 * come before elements from the second.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3199 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3200 * If enough additional memory is available, this takes (__last-__first)-1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3201 * comparisons. Otherwise an NlogN algorithm is used, where N is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3202 * distance(__first,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3203 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3204 * The comparison function should have the same effects on ordering as
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3205 * the function used for the initial sort.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3206 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3207 template<typename _BidirectionalIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3208 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3209 inplace_merge(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3210 _BidirectionalIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3211 _BidirectionalIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3212 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3213 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3214 typedef typename iterator_traits<_BidirectionalIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3215 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3216 typedef typename iterator_traits<_BidirectionalIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3217 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3218
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3219 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3220 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3221 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3222 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3223 _ValueType, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3224 __glibcxx_requires_sorted_pred(__first, __middle, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3225 __glibcxx_requires_sorted_pred(__middle, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3226
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3227 if (__first == __middle || __middle == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3228 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3229
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3230 const _DistanceType __len1 = std::distance(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3231 const _DistanceType __len2 = std::distance(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3232
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3233 _Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3234 __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3235 if (__buf.begin() == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3236 std::__merge_without_buffer(__first, __middle, __last, __len1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3237 __len2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3238 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3239 std::__merge_adaptive(__first, __middle, __last, __len1, __len2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3240 __buf.begin(), _DistanceType(__buf.size()),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3241 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3242 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3243
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3244
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3245 /// This is a helper function for the __merge_sort_loop routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3246 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3247 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3248 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3249 __move_merge(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3250 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3251 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3252 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3253 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3254 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3255 if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3256 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3257 *__result = _GLIBCXX_MOVE(*__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3258 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3259 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3260 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3261 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3262 *__result = _GLIBCXX_MOVE(*__first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3263 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3264 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3265 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3266 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3267 return _GLIBCXX_MOVE3(__first2, __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3268 _GLIBCXX_MOVE3(__first1, __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3269 __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3270 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3271
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3272 /// This is a helper function for the __merge_sort_loop routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3273 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3274 typename _OutputIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3275 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3276 __move_merge(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3277 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3278 _OutputIterator __result, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3279 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3280 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3281 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3282 if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3283 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3284 *__result = _GLIBCXX_MOVE(*__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3285 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3286 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3287 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3288 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3289 *__result = _GLIBCXX_MOVE(*__first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3290 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3291 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3292 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3293 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3294 return _GLIBCXX_MOVE3(__first2, __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3295 _GLIBCXX_MOVE3(__first1, __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3296 __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3297 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3298
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3299 template<typename _RandomAccessIterator1, typename _RandomAccessIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3300 typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3301 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3302 __merge_sort_loop(_RandomAccessIterator1 __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3303 _RandomAccessIterator1 __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3304 _RandomAccessIterator2 __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3305 _Distance __step_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3306 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3307 const _Distance __two_step = 2 * __step_size;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3308
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3309 while (__last - __first >= __two_step)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3310 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3311 __result = std::__move_merge(__first, __first + __step_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3312 __first + __step_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3313 __first + __two_step, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3314 __first += __two_step;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3315 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3316
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3317 __step_size = std::min(_Distance(__last - __first), __step_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3318 std::__move_merge(__first, __first + __step_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3319 __first + __step_size, __last, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3320 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3321
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3322 template<typename _RandomAccessIterator1, typename _RandomAccessIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3323 typename _Distance, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3324 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3325 __merge_sort_loop(_RandomAccessIterator1 __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3326 _RandomAccessIterator1 __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3327 _RandomAccessIterator2 __result, _Distance __step_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3328 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3329 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3330 const _Distance __two_step = 2 * __step_size;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3331
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3332 while (__last - __first >= __two_step)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3333 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3334 __result = std::__move_merge(__first, __first + __step_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3335 __first + __step_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3336 __first + __two_step,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3337 __result, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3338 __first += __two_step;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3339 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3340 __step_size = std::min(_Distance(__last - __first), __step_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3341
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3342 std::__move_merge(__first,__first + __step_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3343 __first + __step_size, __last, __result, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3344 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3345
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3346 template<typename _RandomAccessIterator, typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3347 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3348 __chunk_insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3349 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3350 _Distance __chunk_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3351 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3352 while (__last - __first >= __chunk_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3353 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3354 std::__insertion_sort(__first, __first + __chunk_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3355 __first += __chunk_size;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3356 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3357 std::__insertion_sort(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3358 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3359
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3360 template<typename _RandomAccessIterator, typename _Distance,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3361 typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3362 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3363 __chunk_insertion_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3364 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3365 _Distance __chunk_size, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3366 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3367 while (__last - __first >= __chunk_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3368 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3369 std::__insertion_sort(__first, __first + __chunk_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3370 __first += __chunk_size;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3371 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3372 std::__insertion_sort(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3373 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3374
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3375 enum { _S_chunk_size = 7 };
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3376
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3377 template<typename _RandomAccessIterator, typename _Pointer>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3378 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3379 __merge_sort_with_buffer(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3380 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3381 _Pointer __buffer)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3382 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3383 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3384 _Distance;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3385
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3386 const _Distance __len = __last - __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3387 const _Pointer __buffer_last = __buffer + __len;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3388
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3389 _Distance __step_size = _S_chunk_size;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3390 std::__chunk_insertion_sort(__first, __last, __step_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3391
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3392 while (__step_size < __len)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3393 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3394 std::__merge_sort_loop(__first, __last, __buffer, __step_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3395 __step_size *= 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3396 std::__merge_sort_loop(__buffer, __buffer_last, __first, __step_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3397 __step_size *= 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3398 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3399 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3400
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3401 template<typename _RandomAccessIterator, typename _Pointer, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3402 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3403 __merge_sort_with_buffer(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3404 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3405 _Pointer __buffer, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3406 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3407 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3408 _Distance;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3409
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3410 const _Distance __len = __last - __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3411 const _Pointer __buffer_last = __buffer + __len;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3412
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3413 _Distance __step_size = _S_chunk_size;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3414 std::__chunk_insertion_sort(__first, __last, __step_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3415
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3416 while (__step_size < __len)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3417 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3418 std::__merge_sort_loop(__first, __last, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3419 __step_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3420 __step_size *= 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3421 std::__merge_sort_loop(__buffer, __buffer_last, __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3422 __step_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3423 __step_size *= 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3424 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3425 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3426
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3427 template<typename _RandomAccessIterator, typename _Pointer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3428 typename _Distance>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3429 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3430 __stable_sort_adaptive(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3431 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3432 _Pointer __buffer, _Distance __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3433 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3434 const _Distance __len = (__last - __first + 1) / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3435 const _RandomAccessIterator __middle = __first + __len;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3436 if (__len > __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3437 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3438 std::__stable_sort_adaptive(__first, __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3439 __buffer, __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3440 std::__stable_sort_adaptive(__middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3441 __buffer, __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3442 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3443 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3444 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3445 std::__merge_sort_with_buffer(__first, __middle, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3446 std::__merge_sort_with_buffer(__middle, __last, __buffer);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3447 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3448 std::__merge_adaptive(__first, __middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3449 _Distance(__middle - __first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3450 _Distance(__last - __middle),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3451 __buffer, __buffer_size);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3452 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3453
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3454 template<typename _RandomAccessIterator, typename _Pointer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3455 typename _Distance, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3456 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3457 __stable_sort_adaptive(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3458 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3459 _Pointer __buffer, _Distance __buffer_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3460 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3461 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3462 const _Distance __len = (__last - __first + 1) / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3463 const _RandomAccessIterator __middle = __first + __len;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3464 if (__len > __buffer_size)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3465 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3466 std::__stable_sort_adaptive(__first, __middle, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3467 __buffer_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3468 std::__stable_sort_adaptive(__middle, __last, __buffer,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3469 __buffer_size, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3470 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3471 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3472 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3473 std::__merge_sort_with_buffer(__first, __middle, __buffer, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3474 std::__merge_sort_with_buffer(__middle, __last, __buffer, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3475 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3476 std::__merge_adaptive(__first, __middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3477 _Distance(__middle - __first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3478 _Distance(__last - __middle),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3479 __buffer, __buffer_size,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3480 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3481 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3482
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3483 /// This is a helper function for the stable sorting routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3484 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3485 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3486 __inplace_stable_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3487 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3488 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3489 if (__last - __first < 15)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3490 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3491 std::__insertion_sort(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3492 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3493 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3494 _RandomAccessIterator __middle = __first + (__last - __first) / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3495 std::__inplace_stable_sort(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3496 std::__inplace_stable_sort(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3497 std::__merge_without_buffer(__first, __middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3498 __middle - __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3499 __last - __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3500 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3501
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3502 /// This is a helper function for the stable sorting routines.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3503 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3504 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3505 __inplace_stable_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3506 _RandomAccessIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3507 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3508 if (__last - __first < 15)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3509 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3510 std::__insertion_sort(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3511 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3512 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3513 _RandomAccessIterator __middle = __first + (__last - __first) / 2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3514 std::__inplace_stable_sort(__first, __middle, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3515 std::__inplace_stable_sort(__middle, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3516 std::__merge_without_buffer(__first, __middle, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3517 __middle - __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3518 __last - __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3519 __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3520 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3521
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3522 // stable_sort
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3523
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3524 // Set algorithms: includes, set_union, set_intersection, set_difference,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3525 // set_symmetric_difference. All of these algorithms have the precondition
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3526 // that their input ranges are sorted and the postcondition that their output
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3527 // ranges are sorted.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3528
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3529 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3530 * @brief Determines whether all elements of a sequence exists in a range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3531 * @param __first1 Start of search range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3532 * @param __last1 End of search range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3533 * @param __first2 Start of sequence
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3534 * @param __last2 End of sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3535 * @return True if each element in [__first2,__last2) is contained in order
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3536 * within [__first1,__last1). False otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3537 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3538 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3539 * This operation expects both [__first1,__last1) and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3540 * [__first2,__last2) to be sorted. Searches for the presence of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3541 * each element in [__first2,__last2) within [__first1,__last1).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3542 * The iterators over each range only move forward, so this is a
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3543 * linear algorithm. If an element in [__first2,__last2) is not
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3544 * found before the search iterator reaches @p __last2, false is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3545 * returned.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3546 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3547 template<typename _InputIterator1, typename _InputIterator2>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3548 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3549 includes(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3550 _InputIterator2 __first2, _InputIterator2 __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3551 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3552 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3553 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3554 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3555 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3556
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3557 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3558 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3559 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3560 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3561 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3562 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3563 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3564
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3565 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3566 if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3567 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3568 else if(*__first1 < *__first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3569 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3570 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3571 ++__first1, ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3572
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3573 return __first2 == __last2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3574 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3575
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3576 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3577 * @brief Determines whether all elements of a sequence exists in a range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3578 * using comparison.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3579 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3580 * @param __first1 Start of search range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3581 * @param __last1 End of search range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3582 * @param __first2 Start of sequence
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3583 * @param __last2 End of sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3584 * @param __comp Comparison function to use.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3585 * @return True if each element in [__first2,__last2) is contained
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3586 * in order within [__first1,__last1) according to comp. False
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3587 * otherwise. @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3588 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3589 * This operation expects both [__first1,__last1) and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3590 * [__first2,__last2) to be sorted. Searches for the presence of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3591 * each element in [__first2,__last2) within [__first1,__last1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3592 * using comp to decide. The iterators over each range only move
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3593 * forward, so this is a linear algorithm. If an element in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3594 * [__first2,__last2) is not found before the search iterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3595 * reaches @p __last2, false is returned.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3596 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3597 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3598 typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3599 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3600 includes(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3601 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3602 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3603 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3604 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3605 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3606 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3607 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3608
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3609 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3610 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3611 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3612 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3613 _ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3614 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3615 _ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3616 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3617 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3618
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3619 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3620 if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3621 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3622 else if(__comp(*__first1, *__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3623 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3624 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3625 ++__first1, ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3626
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3627 return __first2 == __last2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3628 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3629
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3630 // nth_element
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3631 // merge
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3632 // set_difference
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3633 // set_intersection
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3634 // set_union
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3635 // stable_sort
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3636 // set_symmetric_difference
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3637 // min_element
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3638 // max_element
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3639
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3640 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3641 * @brief Permute range into the next @e dictionary ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3642 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3643 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3644 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3645 * @return False if wrapped to first permutation, true otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3646 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3647 * Treats all permutations of the range as a set of @e dictionary sorted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3648 * sequences. Permutes the current sequence into the next one of this set.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3649 * Returns true if there are more sequences to generate. If the sequence
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3650 * is the largest of the set, the smallest is generated and false returned.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3651 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3652 template<typename _BidirectionalIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3653 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3654 next_permutation(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3655 _BidirectionalIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3656 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3657 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3658 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3659 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3660 __glibcxx_function_requires(_LessThanComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3661 typename iterator_traits<_BidirectionalIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3662 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3663
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3664 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3665 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3666 _BidirectionalIterator __i = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3667 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3668 if (__i == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3669 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3670 __i = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3671 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3672
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3673 for(;;)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3674 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3675 _BidirectionalIterator __ii = __i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3676 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3677 if (*__i < *__ii)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3678 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3679 _BidirectionalIterator __j = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3680 while (!(*__i < *--__j))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3681 {}
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3682 std::iter_swap(__i, __j);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3683 std::reverse(__ii, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3684 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3685 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3686 if (__i == __first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3687 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3688 std::reverse(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3689 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3690 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3691 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3692 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3693
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3694 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3695 * @brief Permute range into the next @e dictionary ordering using
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3696 * comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3697 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3698 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3699 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3700 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3701 * @return False if wrapped to first permutation, true otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3702 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3703 * Treats all permutations of the range [__first,__last) as a set of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3704 * @e dictionary sorted sequences ordered by @p __comp. Permutes the current
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3705 * sequence into the next one of this set. Returns true if there are more
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3706 * sequences to generate. If the sequence is the largest of the set, the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3707 * smallest is generated and false returned.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3708 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3709 template<typename _BidirectionalIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3710 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3711 next_permutation(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3712 _BidirectionalIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3713 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3714 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3715 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3716 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3717 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3718 typename iterator_traits<_BidirectionalIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3719 typename iterator_traits<_BidirectionalIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3720 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3721
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3722 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3723 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3724 _BidirectionalIterator __i = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3725 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3726 if (__i == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3727 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3728 __i = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3729 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3730
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3731 for(;;)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3732 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3733 _BidirectionalIterator __ii = __i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3734 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3735 if (__comp(*__i, *__ii))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3736 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3737 _BidirectionalIterator __j = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3738 while (!bool(__comp(*__i, *--__j)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3739 {}
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3740 std::iter_swap(__i, __j);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3741 std::reverse(__ii, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3742 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3743 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3744 if (__i == __first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3745 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3746 std::reverse(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3747 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3748 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3749 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3750 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3751
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3752 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3753 * @brief Permute range into the previous @e dictionary ordering.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3754 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3755 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3756 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3757 * @return False if wrapped to last permutation, true otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3758 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3759 * Treats all permutations of the range as a set of @e dictionary sorted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3760 * sequences. Permutes the current sequence into the previous one of this
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3761 * set. Returns true if there are more sequences to generate. If the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3762 * sequence is the smallest of the set, the largest is generated and false
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3763 * returned.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3764 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3765 template<typename _BidirectionalIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3766 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3767 prev_permutation(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3768 _BidirectionalIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3769 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3770 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3771 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3772 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3773 __glibcxx_function_requires(_LessThanComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3774 typename iterator_traits<_BidirectionalIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3775 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3776
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3777 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3778 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3779 _BidirectionalIterator __i = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3780 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3781 if (__i == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3782 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3783 __i = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3784 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3785
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3786 for(;;)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3787 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3788 _BidirectionalIterator __ii = __i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3789 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3790 if (*__ii < *__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3791 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3792 _BidirectionalIterator __j = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3793 while (!(*--__j < *__i))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3794 {}
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3795 std::iter_swap(__i, __j);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3796 std::reverse(__ii, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3797 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3798 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3799 if (__i == __first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3800 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3801 std::reverse(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3802 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3803 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3804 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3805 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3806
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3807 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3808 * @brief Permute range into the previous @e dictionary ordering using
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3809 * comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3810 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3811 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3812 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3813 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3814 * @return False if wrapped to last permutation, true otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3815 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3816 * Treats all permutations of the range [__first,__last) as a set of
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3817 * @e dictionary sorted sequences ordered by @p __comp. Permutes the current
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3818 * sequence into the previous one of this set. Returns true if there are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3819 * more sequences to generate. If the sequence is the smallest of the set,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3820 * the largest is generated and false returned.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3821 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3822 template<typename _BidirectionalIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3823 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3824 prev_permutation(_BidirectionalIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3825 _BidirectionalIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3826 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3827 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3828 __glibcxx_function_requires(_BidirectionalIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3829 _BidirectionalIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3830 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3831 typename iterator_traits<_BidirectionalIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3832 typename iterator_traits<_BidirectionalIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3833 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3834
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3835 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3836 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3837 _BidirectionalIterator __i = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3838 ++__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3839 if (__i == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3840 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3841 __i = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3842 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3843
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3844 for(;;)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3845 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3846 _BidirectionalIterator __ii = __i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3847 --__i;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3848 if (__comp(*__ii, *__i))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3849 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3850 _BidirectionalIterator __j = __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3851 while (!bool(__comp(*--__j, *__i)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3852 {}
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3853 std::iter_swap(__i, __j);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3854 std::reverse(__ii, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3855 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3856 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3857 if (__i == __first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3858 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3859 std::reverse(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3860 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3861 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3862 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3863 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3864
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3865 // replace
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3866 // replace_if
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3867
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3868 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3869 * @brief Copy a sequence, replacing each element of one value with another
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3870 * value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3871 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3872 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3873 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3874 * @param __old_value The value to be replaced.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3875 * @param __new_value The replacement value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3876 * @return The end of the output sequence, @p result+(last-first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3877 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3878 * Copies each element in the input range @p [__first,__last) to the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3879 * output range @p [__result,__result+(__last-__first)) replacing elements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3880 * equal to @p __old_value with @p __new_value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3881 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3882 template<typename _InputIterator, typename _OutputIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3883 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3884 replace_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3885 _OutputIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3886 const _Tp& __old_value, const _Tp& __new_value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3887 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3888 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3889 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3890 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3891 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3892 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3893 typename iterator_traits<_InputIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3894 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3895
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3896 for (; __first != __last; ++__first, ++__result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3897 if (*__first == __old_value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3898 *__result = __new_value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3899 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3900 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3901 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3902 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3903
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3904 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3905 * @brief Copy a sequence, replacing each value for which a predicate
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3906 * returns true with another value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3907 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3908 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3909 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3910 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3911 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3912 * @param __new_value The replacement value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3913 * @return The end of the output sequence, @p __result+(__last-__first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3914 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3915 * Copies each element in the range @p [__first,__last) to the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3916 * @p [__result,__result+(__last-__first)) replacing elements for which
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3917 * @p __pred returns true with @p __new_value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3918 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3919 template<typename _InputIterator, typename _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3920 typename _Predicate, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3921 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3922 replace_copy_if(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3923 _OutputIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3924 _Predicate __pred, const _Tp& __new_value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3925 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3926 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3927 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3928 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3929 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3930 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3931 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3932 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3933
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3934 for (; __first != __last; ++__first, ++__result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3935 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3936 *__result = __new_value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3937 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3938 *__result = *__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3939 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3940 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3941
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3942 #if __cplusplus >= 201103L
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3943 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3944 * @brief Determines whether the elements of a sequence are sorted.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3945 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3946 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3947 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3948 * @return True if the elements are sorted, false otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3949 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3950 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3951 inline bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3952 is_sorted(_ForwardIterator __first, _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3953 { return std::is_sorted_until(__first, __last) == __last; }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3954
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3955 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3956 * @brief Determines whether the elements of a sequence are sorted
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3957 * according to a comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3958 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3959 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3960 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3961 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3962 * @return True if the elements are sorted, false otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3963 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3964 template<typename _ForwardIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3965 inline bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3966 is_sorted(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3967 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3968 { return std::is_sorted_until(__first, __last, __comp) == __last; }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3969
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3970 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3971 * @brief Determines the end of a sorted sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3972 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3973 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3974 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3975 * @return An iterator pointing to the last iterator i in [__first, __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3976 * for which the range [__first, i) is sorted.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3977 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3978 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3979 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3980 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3981 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3982 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3983 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3984 __glibcxx_function_requires(_LessThanComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3985 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3986 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3987
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3988 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3989 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3990
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3991 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3992 for (++__next; __next != __last; __first = __next, ++__next)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3993 if (*__next < *__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3994 return __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3995 return __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3996 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3997
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3998 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3999 * @brief Determines the end of a sorted sequence using comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4000 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4001 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4002 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4003 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4004 * @return An iterator pointing to the last iterator i in [__first, __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4005 * for which the range [__first, i) is sorted.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4006 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4007 template<typename _ForwardIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4008 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4009 is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4010 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4011 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4012 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4013 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4014 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4015 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4016 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4017 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4018
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4019 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4020 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4021
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4022 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4023 for (++__next; __next != __last; __first = __next, ++__next)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4024 if (__comp(*__next, *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4025 return __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4026 return __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4027 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4028
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4029 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4030 * @brief Determines min and max at once as an ordered pair.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4031 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4032 * @param __a A thing of arbitrary type.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4033 * @param __b Another thing of arbitrary type.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4034 * @return A pair(__b, __a) if __b is smaller than __a, pair(__a,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4035 * __b) otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4036 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4037 template<typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4038 inline pair<const _Tp&, const _Tp&>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4039 minmax(const _Tp& __a, const _Tp& __b)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4040 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4041 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4042 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4043
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4044 return __b < __a ? pair<const _Tp&, const _Tp&>(__b, __a)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4045 : pair<const _Tp&, const _Tp&>(__a, __b);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4046 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4047
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4048 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4049 * @brief Determines min and max at once as an ordered pair.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4050 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4051 * @param __a A thing of arbitrary type.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4052 * @param __b Another thing of arbitrary type.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4053 * @param __comp A @link comparison_functors comparison functor @endlink.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4054 * @return A pair(__b, __a) if __b is smaller than __a, pair(__a,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4055 * __b) otherwise.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4056 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4057 template<typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4058 inline pair<const _Tp&, const _Tp&>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4059 minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4060 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4061 return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4062 : pair<const _Tp&, const _Tp&>(__a, __b);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4063 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4064
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4065 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4066 * @brief Return a pair of iterators pointing to the minimum and maximum
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4067 * elements in a range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4068 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4069 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4070 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4071 * @return make_pair(m, M), where m is the first iterator i in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4072 * [__first, __last) such that no other element in the range is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4073 * smaller, and where M is the last iterator i in [__first, __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4074 * such that no other element in the range is larger.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4075 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4076 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4077 pair<_ForwardIterator, _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4078 minmax_element(_ForwardIterator __first, _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4079 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4080 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4081 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4082 __glibcxx_function_requires(_LessThanComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4083 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4084 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4085
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4086 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4087 if (__first == __last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4088 || ++__next == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4089 return std::make_pair(__first, __first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4090
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4091 _ForwardIterator __min, __max;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4092 if (*__next < *__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4093 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4094 __min = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4095 __max = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4096 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4097 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4098 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4099 __min = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4100 __max = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4101 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4102
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4103 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4104 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4105
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4106 while (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4107 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4108 __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4109 if (++__next == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4110 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4111 if (*__first < *__min)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4112 __min = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4113 else if (!(*__first < *__max))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4114 __max = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4115 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4116 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4117
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4118 if (*__next < *__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4119 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4120 if (*__next < *__min)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4121 __min = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4122 if (!(*__first < *__max))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4123 __max = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4124 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4125 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4126 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4127 if (*__first < *__min)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4128 __min = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4129 if (!(*__next < *__max))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4130 __max = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4131 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4132
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4133 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4134 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4135 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4136
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4137 return std::make_pair(__min, __max);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4138 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4139
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4140 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4141 * @brief Return a pair of iterators pointing to the minimum and maximum
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4142 * elements in a range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4143 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4144 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4145 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4146 * @param __comp Comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4147 * @return make_pair(m, M), where m is the first iterator i in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4148 * [__first, __last) such that no other element in the range is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4149 * smaller, and where M is the last iterator i in [__first, __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4150 * such that no other element in the range is larger.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4151 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4152 template<typename _ForwardIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4153 pair<_ForwardIterator, _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4154 minmax_element(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4155 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4156 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4157 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4158 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4159 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4160 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4161 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4162 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4163
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4164 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4165 if (__first == __last
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4166 || ++__next == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4167 return std::make_pair(__first, __first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4168
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4169 _ForwardIterator __min, __max;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4170 if (__comp(*__next, *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4171 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4172 __min = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4173 __max = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4174 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4175 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4176 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4177 __min = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4178 __max = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4179 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4180
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4181 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4182 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4183
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4184 while (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4185 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4186 __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4187 if (++__next == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4188 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4189 if (__comp(*__first, *__min))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4190 __min = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4191 else if (!__comp(*__first, *__max))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4192 __max = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4193 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4194 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4195
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4196 if (__comp(*__next, *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4197 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4198 if (__comp(*__next, *__min))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4199 __min = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4200 if (!__comp(*__first, *__max))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4201 __max = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4202 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4203 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4204 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4205 if (__comp(*__first, *__min))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4206 __min = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4207 if (!__comp(*__next, *__max))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4208 __max = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4209 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4210
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4211 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4212 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4213 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4214
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4215 return std::make_pair(__min, __max);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4216 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4217
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4218 // N2722 + DR 915.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4219 template<typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4220 inline _Tp
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4221 min(initializer_list<_Tp> __l)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4222 { return *std::min_element(__l.begin(), __l.end()); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4223
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4224 template<typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4225 inline _Tp
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4226 min(initializer_list<_Tp> __l, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4227 { return *std::min_element(__l.begin(), __l.end(), __comp); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4228
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4229 template<typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4230 inline _Tp
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4231 max(initializer_list<_Tp> __l)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4232 { return *std::max_element(__l.begin(), __l.end()); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4233
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4234 template<typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4235 inline _Tp
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4236 max(initializer_list<_Tp> __l, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4237 { return *std::max_element(__l.begin(), __l.end(), __comp); }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4238
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4239 template<typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4240 inline pair<_Tp, _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4241 minmax(initializer_list<_Tp> __l)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4242 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4243 pair<const _Tp*, const _Tp*> __p =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4244 std::minmax_element(__l.begin(), __l.end());
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4245 return std::make_pair(*__p.first, *__p.second);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4246 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4247
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4248 template<typename _Tp, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4249 inline pair<_Tp, _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4250 minmax(initializer_list<_Tp> __l, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4251 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4252 pair<const _Tp*, const _Tp*> __p =
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4253 std::minmax_element(__l.begin(), __l.end(), __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4254 return std::make_pair(*__p.first, *__p.second);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4255 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4256
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4257 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4258 * @brief Checks whether a permutaion of the second sequence is equal
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4259 * to the first sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4260 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4261 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4262 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4263 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4264 * @return true if there exists a permutation of the elements in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4265 * [__first2, __first2 + (__last1 - __first1)), beginning with
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4266 * ForwardIterator2 begin, such that equal(__first1, __last1, begin)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4267 * returns true; otherwise, returns false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4268 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4269 template<typename _ForwardIterator1, typename _ForwardIterator2>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4270 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4271 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4272 _ForwardIterator2 __first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4273 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4274 // Efficiently compare identical prefixes: O(N) if sequences
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4275 // have the same elements in the same order.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4276 for (; __first1 != __last1; ++__first1, ++__first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4277 if (!(*__first1 == *__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4278 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4279
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4280 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4281 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4282
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4283 // Establish __last2 assuming equal ranges by iterating over the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4284 // rest of the list.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4285 _ForwardIterator2 __last2 = __first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4286 std::advance(__last2, std::distance(__first1, __last1));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4287 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4288 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4289 if (__scan != _GLIBCXX_STD_A::find(__first1, __scan, *__scan))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4290 continue; // We've seen this one before.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4291
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4292 auto __matches = std::count(__first2, __last2, *__scan);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4293 if (0 == __matches
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4294 || std::count(__scan, __last1, *__scan) != __matches)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4295 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4296 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4297 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4298 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4299
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4300 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4301 * @brief Checks whether a permutation of the second sequence is equal
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4302 * to the first sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4303 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4304 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4305 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4306 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4307 * @param __pred A binary predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4308 * @return true if there exists a permutation of the elements in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4309 * the range [__first2, __first2 + (__last1 - __first1)),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4310 * beginning with ForwardIterator2 begin, such that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4311 * equal(__first1, __last1, __begin, __pred) returns true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4312 * otherwise, returns false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4313 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4314 template<typename _ForwardIterator1, typename _ForwardIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4315 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4316 bool
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4317 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4318 _ForwardIterator2 __first2, _BinaryPredicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4319 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4320 // Efficiently compare identical prefixes: O(N) if sequences
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4321 // have the same elements in the same order.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4322 for (; __first1 != __last1; ++__first1, ++__first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4323 if (!bool(__pred(*__first1, *__first2)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4324 break;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4325
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4326 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4327 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4328
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4329 // Establish __last2 assuming equal ranges by iterating over the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4330 // rest of the list.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4331 _ForwardIterator2 __last2 = __first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4332 std::advance(__last2, std::distance(__first1, __last1));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4333 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4334 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4335 using std::placeholders::_1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4336
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4337 if (__scan != _GLIBCXX_STD_A::find_if(__first1, __scan,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4338 std::bind(__pred, _1, *__scan)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4339 continue; // We've seen this one before.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4340
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4341 auto __matches = std::count_if(__first2, __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4342 std::bind(__pred, _1, *__scan));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4343 if (0 == __matches
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4344 || std::count_if(__scan, __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4345 std::bind(__pred, _1, *__scan)) != __matches)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4346 return false;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4347 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4348 return true;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4349 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4350
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4351 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4352 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4353 * @brief Shuffle the elements of a sequence using a uniform random
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4354 * number generator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4355 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4356 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4357 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4358 * @param __g A UniformRandomNumberGenerator (26.5.1.3).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4359 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4360 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4361 * Reorders the elements in the range @p [__first,__last) using @p __g to
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4362 * provide random numbers.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4363 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4364 template<typename _RandomAccessIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4365 typename _UniformRandomNumberGenerator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4366 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4367 shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4368 _UniformRandomNumberGenerator&& __g)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4369 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4370 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4371 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4372 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4373 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4374
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4375 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4376 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4377
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4378 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4379 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4380
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4381 typedef typename std::make_unsigned<_DistanceType>::type __ud_type;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4382 typedef typename std::uniform_int_distribution<__ud_type> __distr_type;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4383 typedef typename __distr_type::param_type __p_type;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4384 __distr_type __d;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4385
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4386 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4387 std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4388 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4389 #endif
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4390
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4391 #endif // C++11
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4392
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4393 _GLIBCXX_END_NAMESPACE_VERSION
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4394
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4395 _GLIBCXX_BEGIN_NAMESPACE_ALGO
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4396
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4397 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4398 * @brief Apply a function to every element of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4399 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4400 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4401 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4402 * @param __f A unary function object.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4403 * @return @p __f (std::move(@p __f) in C++0x).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4404 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4405 * Applies the function object @p __f to each element in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4406 * @p [first,last). @p __f must not modify the order of the sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4407 * If @p __f has a return value it is ignored.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4408 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4409 template<typename _InputIterator, typename _Function>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4410 _Function
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4411 for_each(_InputIterator __first, _InputIterator __last, _Function __f)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4412 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4413 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4414 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4415 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4416 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4417 __f(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4418 return _GLIBCXX_MOVE(__f);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4419 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4420
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4421 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4422 * @brief Find the first occurrence of a value in a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4423 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4424 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4425 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4426 * @param __val The value to find.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4427 * @return The first iterator @c i in the range @p [__first,__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4428 * such that @c *i == @p __val, or @p __last if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4429 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4430 template<typename _InputIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4431 inline _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4432 find(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4433 const _Tp& __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4434 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4435 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4436 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4437 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4438 typename iterator_traits<_InputIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4439 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4440 return std::__find(__first, __last, __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4441 std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4442 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4443
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4444 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4445 * @brief Find the first element in a sequence for which a
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4446 * predicate is true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4447 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4448 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4449 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4450 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4451 * @return The first iterator @c i in the range @p [__first,__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4452 * such that @p __pred(*i) is true, or @p __last if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4453 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4454 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4455 inline _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4456 find_if(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4457 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4458 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4459 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4460 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4461 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4462 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4463 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4464 return std::__find_if(__first, __last, __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4465 std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4466 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4467
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4468 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4469 * @brief Find element from a set in a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4470 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4471 * @param __first1 Start of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4472 * @param __last1 End of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4473 * @param __first2 Start of match candidates.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4474 * @param __last2 End of match candidates.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4475 * @return The first iterator @c i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4476 * @p [__first1,__last1) such that @c *i == @p *(i2) such that i2 is an
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4477 * iterator in [__first2,__last2), or @p __last1 if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4478 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4479 * Searches the range @p [__first1,__last1) for an element that is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4480 * equal to some element in the range [__first2,__last2). If
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4481 * found, returns an iterator in the range [__first1,__last1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4482 * otherwise returns @p __last1.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4483 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4484 template<typename _InputIterator, typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4485 _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4486 find_first_of(_InputIterator __first1, _InputIterator __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4487 _ForwardIterator __first2, _ForwardIterator __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4488 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4489 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4490 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4491 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4492 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4493 typename iterator_traits<_InputIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4494 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4495 __glibcxx_requires_valid_range(__first1, __last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4496 __glibcxx_requires_valid_range(__first2, __last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4497
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4498 for (; __first1 != __last1; ++__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4499 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4500 if (*__first1 == *__iter)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4501 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4502 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4503 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4504
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4505 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4506 * @brief Find element from a set in a sequence using a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4507 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4508 * @param __first1 Start of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4509 * @param __last1 End of range to search.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4510 * @param __first2 Start of match candidates.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4511 * @param __last2 End of match candidates.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4512 * @param __comp Predicate to use.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4513 * @return The first iterator @c i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4514 * @p [__first1,__last1) such that @c comp(*i, @p *(i2)) is true
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4515 * and i2 is an iterator in [__first2,__last2), or @p __last1 if no
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4516 * such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4517 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4518
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4519 * Searches the range @p [__first1,__last1) for an element that is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4520 * equal to some element in the range [__first2,__last2). If
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4521 * found, returns an iterator in the range [__first1,__last1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4522 * otherwise returns @p __last1.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4523 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4524 template<typename _InputIterator, typename _ForwardIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4525 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4526 _InputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4527 find_first_of(_InputIterator __first1, _InputIterator __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4528 _ForwardIterator __first2, _ForwardIterator __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4529 _BinaryPredicate __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4530 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4531 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4532 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4533 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4534 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4535 typename iterator_traits<_InputIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4536 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4537 __glibcxx_requires_valid_range(__first1, __last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4538 __glibcxx_requires_valid_range(__first2, __last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4539
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4540 for (; __first1 != __last1; ++__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4541 for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4542 if (__comp(*__first1, *__iter))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4543 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4544 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4545 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4546
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4547 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4548 * @brief Find two adjacent values in a sequence that are equal.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4549 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4550 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4551 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4552 * @return The first iterator @c i such that @c i and @c i+1 are both
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4553 * valid iterators in @p [__first,__last) and such that @c *i == @c *(i+1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4554 * or @p __last if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4555 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4556 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4557 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4558 adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4559 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4560 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4561 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4562 __glibcxx_function_requires(_EqualityComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4563 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4564 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4565 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4566 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4567 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4568 while(++__next != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4569 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4570 if (*__first == *__next)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4571 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4572 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4573 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4574 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4575 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4576
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4577 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4578 * @brief Find two adjacent values in a sequence using a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4579 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4580 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4581 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4582 * @param __binary_pred A binary predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4583 * @return The first iterator @c i such that @c i and @c i+1 are both
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4584 * valid iterators in @p [__first,__last) and such that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4585 * @p __binary_pred(*i,*(i+1)) is true, or @p __last if no such iterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4586 * exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4587 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4588 template<typename _ForwardIterator, typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4589 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4590 adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4591 _BinaryPredicate __binary_pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4592 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4593 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4594 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4595 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4596 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4597 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4598 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4599 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4600 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4601 _ForwardIterator __next = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4602 while(++__next != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4603 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4604 if (__binary_pred(*__first, *__next))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4605 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4606 __first = __next;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4607 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4608 return __last;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4609 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4610
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4611 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4612 * @brief Count the number of copies of a value in a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4613 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4614 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4615 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4616 * @param __value The value to be counted.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4617 * @return The number of iterators @c i in the range @p [__first,__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4618 * for which @c *i == @p __value
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4619 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4620 template<typename _InputIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4621 typename iterator_traits<_InputIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4622 count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4623 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4624 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4625 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4626 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4627 typename iterator_traits<_InputIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4628 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4629 typename iterator_traits<_InputIterator>::difference_type __n = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4630 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4631 if (*__first == __value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4632 ++__n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4633 return __n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4634 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4635
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4636 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4637 * @brief Count the elements of a sequence for which a predicate is true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4638 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4639 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4640 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4641 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4642 * @return The number of iterators @c i in the range @p [__first,__last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4643 * for which @p __pred(*i) is true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4644 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4645 template<typename _InputIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4646 typename iterator_traits<_InputIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4647 count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4648 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4649 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4650 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4651 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4652 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4653 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4654 typename iterator_traits<_InputIterator>::difference_type __n = 0;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4655 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4656 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4657 ++__n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4658 return __n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4659 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4660
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4661 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4662 * @brief Search a sequence for a matching sub-sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4663 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4664 * @param __first1 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4665 * @param __last1 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4666 * @param __first2 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4667 * @param __last2 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4668 * @return The first iterator @c i in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4669 * [__first1,__last1-(__last2-__first2)) such that @c *(i+N) == @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4670 * *(__first2+N) for each @c N in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4671 * [0,__last2-__first2), or @p __last1 if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4672 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4673 * Searches the range @p [__first1,__last1) for a sub-sequence that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4674 * compares equal value-by-value with the sequence given by @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4675 * [__first2,__last2) and returns an iterator to the first element
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4676 * of the sub-sequence, or @p __last1 if the sub-sequence is not
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4677 * found.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4678 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4679 * Because the sub-sequence must lie completely within the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4680 * [__first1,__last1) it must start at a position less than @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4681 * __last1-(__last2-__first2) where @p __last2-__first2 is the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4682 * length of the sub-sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4683 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4684 * This means that the returned iterator @c i will be in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4685 * @p [__first1,__last1-(__last2-__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4686 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4687 template<typename _ForwardIterator1, typename _ForwardIterator2>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4688 _ForwardIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4689 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4690 _ForwardIterator2 __first2, _ForwardIterator2 __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4691 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4692 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4693 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4694 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4695 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4696 typename iterator_traits<_ForwardIterator1>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4697 typename iterator_traits<_ForwardIterator2>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4698 __glibcxx_requires_valid_range(__first1, __last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4699 __glibcxx_requires_valid_range(__first2, __last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4700
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4701 // Test for empty ranges
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4702 if (__first1 == __last1 || __first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4703 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4704
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4705 // Test for a pattern of length 1.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4706 _ForwardIterator2 __p1(__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4707 if (++__p1 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4708 return _GLIBCXX_STD_A::find(__first1, __last1, *__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4709
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4710 // General case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4711 _ForwardIterator2 __p;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4712 _ForwardIterator1 __current = __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4713
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4714 for (;;)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4715 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4716 __first1 = _GLIBCXX_STD_A::find(__first1, __last1, *__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4717 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4718 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4719
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4720 __p = __p1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4721 __current = __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4722 if (++__current == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4723 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4724
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4725 while (*__current == *__p)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4726 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4727 if (++__p == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4728 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4729 if (++__current == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4730 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4731 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4732 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4733 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4734 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4735 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4736
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4737 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4738 * @brief Search a sequence for a matching sub-sequence using a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4739 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4740 * @param __first1 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4741 * @param __last1 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4742 * @param __first2 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4743 * @param __last2 A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4744 * @param __predicate A binary predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4745 * @return The first iterator @c i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4746 * @p [__first1,__last1-(__last2-__first2)) such that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4747 * @p __predicate(*(i+N),*(__first2+N)) is true for each @c N in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4748 * @p [0,__last2-__first2), or @p __last1 if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4749 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4750 * Searches the range @p [__first1,__last1) for a sub-sequence that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4751 * compares equal value-by-value with the sequence given by @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4752 * [__first2,__last2), using @p __predicate to determine equality,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4753 * and returns an iterator to the first element of the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4754 * sub-sequence, or @p __last1 if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4755 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4756 * @see search(_ForwardIter1, _ForwardIter1, _ForwardIter2, _ForwardIter2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4757 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4758 template<typename _ForwardIterator1, typename _ForwardIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4759 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4760 _ForwardIterator1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4761 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4762 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4763 _BinaryPredicate __predicate)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4764 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4765 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4766 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4767 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4768 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4769 typename iterator_traits<_ForwardIterator1>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4770 typename iterator_traits<_ForwardIterator2>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4771 __glibcxx_requires_valid_range(__first1, __last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4772 __glibcxx_requires_valid_range(__first2, __last2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4773
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4774 // Test for empty ranges
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4775 if (__first1 == __last1 || __first2 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4776 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4777
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4778 // Test for a pattern of length 1.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4779 _ForwardIterator2 __p1(__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4780 if (++__p1 == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4781 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4782 while (__first1 != __last1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4783 && !bool(__predicate(*__first1, *__first2)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4784 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4785 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4786 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4787
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4788 // General case.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4789 _ForwardIterator2 __p;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4790 _ForwardIterator1 __current = __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4791
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4792 for (;;)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4793 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4794 while (__first1 != __last1
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4795 && !bool(__predicate(*__first1, *__first2)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4796 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4797 if (__first1 == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4798 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4799
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4800 __p = __p1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4801 __current = __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4802 if (++__current == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4803 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4804
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4805 while (__predicate(*__current, *__p))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4806 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4807 if (++__p == __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4808 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4809 if (++__current == __last1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4810 return __last1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4811 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4812 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4813 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4814 return __first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4815 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4816
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4817
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4818 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4819 * @brief Search a sequence for a number of consecutive values.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4820 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4821 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4822 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4823 * @param __count The number of consecutive values.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4824 * @param __val The value to find.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4825 * @return The first iterator @c i in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4826 * [__first,__last-__count) such that @c *(i+N) == @p __val for
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4827 * each @c N in the range @p [0,__count), or @p __last if no such
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4828 * iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4829 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4830 * Searches the range @p [__first,__last) for @p count consecutive elements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4831 * equal to @p __val.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4832 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4833 template<typename _ForwardIterator, typename _Integer, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4834 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4835 search_n(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4836 _Integer __count, const _Tp& __val)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4837 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4838 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4839 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4840 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4841 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4842 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4843
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4844 if (__count <= 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4845 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4846 if (__count == 1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4847 return _GLIBCXX_STD_A::find(__first, __last, __val);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4848 return std::__search_n(__first, __last, __count, __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4849 std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4850 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4851
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4852
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4853 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4854 * @brief Search a sequence for a number of consecutive values using a
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4855 * predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4856 * @ingroup non_mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4857 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4858 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4859 * @param __count The number of consecutive values.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4860 * @param __val The value to find.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4861 * @param __binary_pred A binary predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4862 * @return The first iterator @c i in the range @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4863 * [__first,__last-__count) such that @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4864 * __binary_pred(*(i+N),__val) is true for each @c N in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4865 * @p [0,__count), or @p __last if no such iterator exists.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4866 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4867 * Searches the range @p [__first,__last) for @p __count
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4868 * consecutive elements for which the predicate returns true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4869 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4870 template<typename _ForwardIterator, typename _Integer, typename _Tp,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4871 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4872 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4873 search_n(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4874 _Integer __count, const _Tp& __val,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4875 _BinaryPredicate __binary_pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4876 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4877 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4878 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4879 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4880 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4881 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4882
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4883 if (__count <= 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4884 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4885 if (__count == 1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4886 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4887 while (__first != __last && !bool(__binary_pred(*__first, __val)))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4888 ++__first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4889 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4890 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4891 return std::__search_n(__first, __last, __count, __val, __binary_pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4892 std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4893 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4894
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4895
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4896 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4897 * @brief Perform an operation on a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4898 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4899 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4900 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4901 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4902 * @param __unary_op A unary operator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4903 * @return An output iterator equal to @p __result+(__last-__first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4904 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4905 * Applies the operator to each element in the input range and assigns
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4906 * the results to successive elements of the output sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4907 * Evaluates @p *(__result+N)=unary_op(*(__first+N)) for each @c N in the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4908 * range @p [0,__last-__first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4909 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4910 * @p unary_op must not alter its argument.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4911 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4912 template<typename _InputIterator, typename _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4913 typename _UnaryOperation>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4914 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4915 transform(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4916 _OutputIterator __result, _UnaryOperation __unary_op)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4917 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4918 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4919 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4920 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4921 // "the type returned by a _UnaryOperation"
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4922 __typeof__(__unary_op(*__first))>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4923 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4924
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4925 for (; __first != __last; ++__first, ++__result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4926 *__result = __unary_op(*__first);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4927 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4928 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4929
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4930 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4931 * @brief Perform an operation on corresponding elements of two sequences.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4932 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4933 * @param __first1 An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4934 * @param __last1 An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4935 * @param __first2 An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4936 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4937 * @param __binary_op A binary operator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4938 * @return An output iterator equal to @p result+(last-first).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4939 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4940 * Applies the operator to the corresponding elements in the two
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4941 * input ranges and assigns the results to successive elements of the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4942 * output sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4943 * Evaluates @p
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4944 * *(__result+N)=__binary_op(*(__first1+N),*(__first2+N)) for each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4945 * @c N in the range @p [0,__last1-__first1).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4946 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4947 * @p binary_op must not alter either of its arguments.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4948 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4949 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4950 typename _OutputIterator, typename _BinaryOperation>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4951 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4952 transform(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4953 _InputIterator2 __first2, _OutputIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4954 _BinaryOperation __binary_op)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4955 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4956 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4957 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4958 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4959 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4960 // "the type returned by a _BinaryOperation"
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4961 __typeof__(__binary_op(*__first1,*__first2))>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4962 __glibcxx_requires_valid_range(__first1, __last1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4963
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4964 for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4965 *__result = __binary_op(*__first1, *__first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4966 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4967 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4968
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4969 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4970 * @brief Replace each occurrence of one value in a sequence with another
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4971 * value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4972 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4973 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4974 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4975 * @param __old_value The value to be replaced.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4976 * @param __new_value The replacement value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4977 * @return replace() returns no value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4978 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4979 * For each iterator @c i in the range @p [__first,__last) if @c *i ==
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4980 * @p __old_value then the assignment @c *i = @p __new_value is performed.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4981 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4982 template<typename _ForwardIterator, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4983 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4984 replace(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4985 const _Tp& __old_value, const _Tp& __new_value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4986 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4987 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4988 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4989 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4990 __glibcxx_function_requires(_EqualOpConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4991 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4992 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4993 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4994 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4995
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4996 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4997 if (*__first == __old_value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4998 *__first = __new_value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4999 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5000
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5001 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5002 * @brief Replace each value in a sequence for which a predicate returns
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5003 * true with another value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5004 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5005 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5006 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5007 * @param __pred A predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5008 * @param __new_value The replacement value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5009 * @return replace_if() returns no value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5010 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5011 * For each iterator @c i in the range @p [__first,__last) if @p __pred(*i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5012 * is true then the assignment @c *i = @p __new_value is performed.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5013 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5014 template<typename _ForwardIterator, typename _Predicate, typename _Tp>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5015 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5016 replace_if(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5017 _Predicate __pred, const _Tp& __new_value)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5018 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5019 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5020 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5021 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5022 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5023 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5024 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5025 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5026 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5027
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5028 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5029 if (__pred(*__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5030 *__first = __new_value;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5031 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5032
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5033 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5034 * @brief Assign the result of a function object to each value in a
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5035 * sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5036 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5037 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5038 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5039 * @param __gen A function object taking no arguments and returning
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5040 * std::iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5041 * @return generate() returns no value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5042 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5043 * Performs the assignment @c *i = @p __gen() for each @c i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5044 * @p [__first,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5045 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5046 template<typename _ForwardIterator, typename _Generator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5047 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5048 generate(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5049 _Generator __gen)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5050 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5051 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5052 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5053 __glibcxx_function_requires(_GeneratorConcept<_Generator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5054 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5055 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5056
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5057 for (; __first != __last; ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5058 *__first = __gen();
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5059 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5060
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5061 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5062 * @brief Assign the result of a function object to each value in a
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5063 * sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5064 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5065 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5066 * @param __n The length of the sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5067 * @param __gen A function object taking no arguments and returning
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5068 * std::iterator_traits<_ForwardIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5069 * @return The end of the sequence, @p __first+__n
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5070 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5071 * Performs the assignment @c *i = @p __gen() for each @c i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5072 * @p [__first,__first+__n).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5073 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5074 * _GLIBCXX_RESOLVE_LIB_DEFECTS
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5075 * DR 865. More algorithms that throw away information
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5076 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5077 template<typename _OutputIterator, typename _Size, typename _Generator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5078 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5079 generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5080 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5081 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5082 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5083 // "the type returned by a _Generator"
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5084 __typeof__(__gen())>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5085
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5086 for (__decltype(__n + 0) __niter = __n;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5087 __niter > 0; --__niter, ++__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5088 *__first = __gen();
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5089 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5090 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5091
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5092
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5093 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5094 * @brief Copy a sequence, removing consecutive duplicate values.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5095 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5096 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5097 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5098 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5099 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5100 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5101 * Copies each element in the range @p [__first,__last) to the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5102 * beginning at @p __result, except that only the first element is copied
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5103 * from groups of consecutive elements that compare equal.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5104 * unique_copy() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5105 * copied is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5106 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5107 * _GLIBCXX_RESOLVE_LIB_DEFECTS
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5108 * DR 241. Does unique_copy() require CopyConstructible and Assignable?
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5109 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5110 * _GLIBCXX_RESOLVE_LIB_DEFECTS
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5111 * DR 538. 241 again: Does unique_copy() require CopyConstructible and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5112 * Assignable?
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5113 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5114 template<typename _InputIterator, typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5115 inline _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5116 unique_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5117 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5118 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5119 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5120 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5121 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5122 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5123 __glibcxx_function_requires(_EqualityComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5124 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5125 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5126
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5127 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5128 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5129 return std::__unique_copy(__first, __last, __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5130 std::__iterator_category(__first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5131 std::__iterator_category(__result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5132 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5133
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5134 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5135 * @brief Copy a sequence, removing consecutive values using a predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5136 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5137 * @param __first An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5138 * @param __last An input iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5139 * @param __result An output iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5140 * @param __binary_pred A binary predicate.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5141 * @return An iterator designating the end of the resulting sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5142 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5143 * Copies each element in the range @p [__first,__last) to the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5144 * beginning at @p __result, except that only the first element is copied
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5145 * from groups of consecutive elements for which @p __binary_pred returns
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5146 * true.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5147 * unique_copy() is stable, so the relative order of elements that are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5148 * copied is unchanged.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5149 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5150 * _GLIBCXX_RESOLVE_LIB_DEFECTS
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5151 * DR 241. Does unique_copy() require CopyConstructible and Assignable?
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5152 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5153 template<typename _InputIterator, typename _OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5154 typename _BinaryPredicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5155 inline _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5156 unique_copy(_InputIterator __first, _InputIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5157 _OutputIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5158 _BinaryPredicate __binary_pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5159 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5160 // concept requirements -- predicates checked later
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5161 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5162 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5163 typename iterator_traits<_InputIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5164 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5165
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5166 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5167 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5168 return std::__unique_copy(__first, __last, __result, __binary_pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5169 std::__iterator_category(__first),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5170 std::__iterator_category(__result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5171 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5172
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5173
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5174 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5175 * @brief Randomly shuffle the elements of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5176 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5177 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5178 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5179 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5180 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5181 * Reorder the elements in the range @p [__first,__last) using a random
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5182 * distribution, so that every possible ordering of the sequence is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5183 * equally likely.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5184 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5185 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5186 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5187 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5188 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5189 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5190 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5191 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5192 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5193
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5194 if (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5195 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5196 std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1)));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5197 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5198
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5199 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5200 * @brief Shuffle the elements of a sequence using a random number
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5201 * generator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5202 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5203 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5204 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5205 * @param __rand The RNG functor or function.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5206 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5207 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5208 * Reorders the elements in the range @p [__first,__last) using @p __rand to
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5209 * provide a random distribution. Calling @p __rand(N) for a positive
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5210 * integer @p N should return a randomly chosen integer from the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5211 * range [0,N).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5212 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5213 template<typename _RandomAccessIterator, typename _RandomNumberGenerator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5214 void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5215 random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5216 #if __cplusplus >= 201103L
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5217 _RandomNumberGenerator&& __rand)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5218 #else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5219 _RandomNumberGenerator& __rand)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5220 #endif
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5221 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5222 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5223 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5224 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5225 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5226
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5227 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5228 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5229 for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5230 std::iter_swap(__i, __first + __rand((__i - __first) + 1));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5231 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5232
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5233
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5234 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5235 * @brief Move elements for which a predicate is true to the beginning
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5236 * of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5237 * @ingroup mutating_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5238 * @param __first A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5239 * @param __last A forward iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5240 * @param __pred A predicate functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5241 * @return An iterator @p middle such that @p __pred(i) is true for each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5242 * iterator @p i in the range @p [__first,middle) and false for each @p i
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5243 * in the range @p [middle,__last).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5244 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5245 * @p __pred must not modify its operand. @p partition() does not preserve
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5246 * the relative ordering of elements in each group, use
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5247 * @p stable_partition() if this is needed.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5248 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5249 template<typename _ForwardIterator, typename _Predicate>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5250 inline _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5251 partition(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5252 _Predicate __pred)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5253 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5254 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5255 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5256 _ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5257 __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5258 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5259 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5260
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5261 return std::__partition(__first, __last, __pred,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5262 std::__iterator_category(__first));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5263 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5264
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5265
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5266
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5267 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5268 * @brief Sort the smallest elements of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5269 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5270 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5271 * @param __middle Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5272 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5273 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5274 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5275 * Sorts the smallest @p (__middle-__first) elements in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5276 * @p [first,last) and moves them to the range @p [__first,__middle). The
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5277 * order of the remaining elements in the range @p [__middle,__last) is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5278 * undefined.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5279 * After the sort if @e i and @e j are iterators in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5280 * @p [__first,__middle) such that i precedes j and @e k is an iterator in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5281 * the range @p [__middle,__last) then *j<*i and *k<*i are both false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5282 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5283 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5284 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5285 partial_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5286 _RandomAccessIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5287 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5288 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5289 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5290 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5291
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5292 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5293 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5294 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5295 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5296 __glibcxx_requires_valid_range(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5297 __glibcxx_requires_valid_range(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5298
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5299 std::__heap_select(__first, __middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5300 std::sort_heap(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5301 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5302
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5303 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5304 * @brief Sort the smallest elements of a sequence using a predicate
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5305 * for comparison.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5306 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5307 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5308 * @param __middle Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5309 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5310 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5311 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5312 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5313 * Sorts the smallest @p (__middle-__first) elements in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5314 * @p [__first,__last) and moves them to the range @p [__first,__middle). The
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5315 * order of the remaining elements in the range @p [__middle,__last) is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5316 * undefined.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5317 * After the sort if @e i and @e j are iterators in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5318 * @p [__first,__middle) such that i precedes j and @e k is an iterator in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5319 * the range @p [__middle,__last) then @p *__comp(j,*i) and @p __comp(*k,*i)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5320 * are both false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5321 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5322 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5323 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5324 partial_sort(_RandomAccessIterator __first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5325 _RandomAccessIterator __middle,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5326 _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5327 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5328 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5329 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5330 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5331
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5332 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5333 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5334 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5335 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5336 _ValueType, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5337 __glibcxx_requires_valid_range(__first, __middle);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5338 __glibcxx_requires_valid_range(__middle, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5339
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5340 std::__heap_select(__first, __middle, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5341 std::sort_heap(__first, __middle, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5342 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5343
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5344 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5345 * @brief Sort a sequence just enough to find a particular position.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5346 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5347 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5348 * @param __nth Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5349 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5350 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5351 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5352 * Rearranges the elements in the range @p [__first,__last) so that @p *__nth
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5353 * is the same element that would have been in that position had the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5354 * whole sequence been sorted. The elements either side of @p *__nth are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5355 * not completely sorted, but for any iterator @e i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5356 * @p [__first,__nth) and any iterator @e j in the range @p [__nth,__last) it
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5357 * holds that *j < *i is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5358 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5359 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5360 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5361 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5362 _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5363 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5364 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5365 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5366
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5367 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5368 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5369 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5370 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5371 __glibcxx_requires_valid_range(__first, __nth);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5372 __glibcxx_requires_valid_range(__nth, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5373
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5374 if (__first == __last || __nth == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5375 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5376
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5377 std::__introselect(__first, __nth, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5378 std::__lg(__last - __first) * 2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5379 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5380
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5381 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5382 * @brief Sort a sequence just enough to find a particular position
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5383 * using a predicate for comparison.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5384 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5385 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5386 * @param __nth Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5387 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5388 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5389 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5390 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5391 * Rearranges the elements in the range @p [__first,__last) so that @p *__nth
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5392 * is the same element that would have been in that position had the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5393 * whole sequence been sorted. The elements either side of @p *__nth are
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5394 * not completely sorted, but for any iterator @e i in the range
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5395 * @p [__first,__nth) and any iterator @e j in the range @p [__nth,__last) it
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5396 * holds that @p __comp(*j,*i) is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5397 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5398 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5399 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5400 nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5401 _RandomAccessIterator __last, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5402 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5403 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5404 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5405
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5406 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5407 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5408 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5409 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5410 _ValueType, _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5411 __glibcxx_requires_valid_range(__first, __nth);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5412 __glibcxx_requires_valid_range(__nth, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5413
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5414 if (__first == __last || __nth == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5415 return;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5416
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5417 std::__introselect(__first, __nth, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5418 std::__lg(__last - __first) * 2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5419 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5420
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5421
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5422 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5423 * @brief Sort the elements of a sequence.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5424 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5425 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5426 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5427 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5428 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5429 * Sorts the elements in the range @p [__first,__last) in ascending order,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5430 * such that for each iterator @e i in the range @p [__first,__last-1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5431 * *(i+1)<*i is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5432 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5433 * The relative ordering of equivalent elements is not preserved, use
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5434 * @p stable_sort() if this is needed.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5435 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5436 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5437 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5438 sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5439 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5440 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5441 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5442
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5443 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5444 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5445 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5446 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5447 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5448
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5449 if (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5450 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5451 std::__introsort_loop(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5452 std::__lg(__last - __first) * 2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5453 std::__final_insertion_sort(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5454 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5455 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5456
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5457 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5458 * @brief Sort the elements of a sequence using a predicate for comparison.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5459 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5460 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5461 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5462 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5463 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5464 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5465 * Sorts the elements in the range @p [__first,__last) in ascending order,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5466 * such that @p __comp(*(i+1),*i) is false for every iterator @e i in the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5467 * range @p [__first,__last-1).
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5468 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5469 * The relative ordering of equivalent elements is not preserved, use
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5470 * @p stable_sort() if this is needed.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5471 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5472 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5473 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5474 sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5475 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5476 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5477 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5478 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5479
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5480 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5481 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5482 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5483 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _ValueType,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5484 _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5485 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5486
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5487 if (__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5488 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5489 std::__introsort_loop(__first, __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5490 std::__lg(__last - __first) * 2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5491 std::__final_insertion_sort(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5492 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5493 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5494
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5495 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5496 * @brief Merges two sorted ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5497 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5498 * @param __first1 An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5499 * @param __first2 Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5500 * @param __last1 Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5501 * @param __last2 Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5502 * @param __result An iterator pointing to the end of the merged range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5503 * @return An iterator pointing to the first element <em>not less
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5504 * than</em> @e val.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5505 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5506 * Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5507 * the sorted range @p [__result, __result + (__last1-__first1) +
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5508 * (__last2-__first2)). Both input ranges must be sorted, and the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5509 * output range must not overlap with either of the input ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5510 * The sort is @e stable, that is, for equivalent elements in the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5511 * two ranges, elements from the first range will always come
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5512 * before elements from the second.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5513 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5514 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5515 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5516 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5517 merge(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5518 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5519 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5520 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5521 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5522 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5523 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5524 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5525
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5526 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5527 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5528 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5529 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5530 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5531 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5532 _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5533 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5534 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5535 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5536
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5537 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5538 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5539 if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5540 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5541 *__result = *__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5542 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5543 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5544 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5545 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5546 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5547 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5548 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5549 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5550 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5551 return std::copy(__first2, __last2, std::copy(__first1, __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5552 __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5553 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5554
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5555 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5556 * @brief Merges two sorted ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5557 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5558 * @param __first1 An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5559 * @param __first2 Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5560 * @param __last1 Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5561 * @param __last2 Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5562 * @param __result An iterator pointing to the end of the merged range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5563 * @param __comp A functor to use for comparisons.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5564 * @return An iterator pointing to the first element "not less
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5565 * than" @e val.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5566 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5567 * Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5568 * the sorted range @p [__result, __result + (__last1-__first1) +
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5569 * (__last2-__first2)). Both input ranges must be sorted, and the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5570 * output range must not overlap with either of the input ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5571 * The sort is @e stable, that is, for equivalent elements in the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5572 * two ranges, elements from the first range will always come
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5573 * before elements from the second.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5574 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5575 * The comparison function should have the same effects on ordering as
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5576 * the function used for the initial sort.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5577 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5578 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5579 typename _OutputIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5580 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5581 merge(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5582 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5583 _OutputIterator __result, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5584 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5585 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5586 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5587 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5588 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5589
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5590 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5591 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5592 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5593 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5594 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5595 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5596 _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5597 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5598 _ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5599 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5600 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5601
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5602 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5603 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5604 if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5605 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5606 *__result = *__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5607 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5608 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5609 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5610 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5611 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5612 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5613 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5614 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5615 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5616 return std::copy(__first2, __last2, std::copy(__first1, __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5617 __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5618 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5619
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5620
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5621 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5622 * @brief Sort the elements of a sequence, preserving the relative order
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5623 * of equivalent elements.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5624 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5625 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5626 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5627 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5628 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5629 * Sorts the elements in the range @p [__first,__last) in ascending order,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5630 * such that for each iterator @p i in the range @p [__first,__last-1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5631 * @p *(i+1)<*i is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5632 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5633 * The relative ordering of equivalent elements is preserved, so any two
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5634 * elements @p x and @p y in the range @p [__first,__last) such that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5635 * @p x<y is false and @p y<x is false will have the same relative
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5636 * ordering after calling @p stable_sort().
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5637 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5638 template<typename _RandomAccessIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5639 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5640 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5641 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5642 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5643 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5644 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5645 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5646
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5647 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5648 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5649 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5650 __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5651 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5652
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5653 _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5654 __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5655 if (__buf.begin() == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5656 std::__inplace_stable_sort(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5657 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5658 std::__stable_sort_adaptive(__first, __last, __buf.begin(),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5659 _DistanceType(__buf.size()));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5660 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5661
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5662 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5663 * @brief Sort the elements of a sequence using a predicate for comparison,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5664 * preserving the relative order of equivalent elements.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5665 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5666 * @param __first An iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5667 * @param __last Another iterator.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5668 * @param __comp A comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5669 * @return Nothing.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5670 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5671 * Sorts the elements in the range @p [__first,__last) in ascending order,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5672 * such that for each iterator @p i in the range @p [__first,__last-1),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5673 * @p __comp(*(i+1),*i) is false.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5674 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5675 * The relative ordering of equivalent elements is preserved, so any two
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5676 * elements @p x and @p y in the range @p [__first,__last) such that
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5677 * @p __comp(x,y) is false and @p __comp(y,x) is false will have the same
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5678 * relative ordering after calling @p stable_sort().
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5679 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5680 template<typename _RandomAccessIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5681 inline void
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5682 stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5683 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5684 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5685 typedef typename iterator_traits<_RandomAccessIterator>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5686 _ValueType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5687 typedef typename iterator_traits<_RandomAccessIterator>::difference_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5688 _DistanceType;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5689
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5690 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5691 __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5692 _RandomAccessIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5693 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5694 _ValueType,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5695 _ValueType>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5696 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5697
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5698 _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5699 __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5700 if (__buf.begin() == 0)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5701 std::__inplace_stable_sort(__first, __last, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5702 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5703 std::__stable_sort_adaptive(__first, __last, __buf.begin(),
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5704 _DistanceType(__buf.size()), __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5705 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5706
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5707
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5708 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5709 * @brief Return the union of two sorted ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5710 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5711 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5712 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5713 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5714 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5715 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5716 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5717 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5718 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5719 * each range in order to the output range. Iterators increment for each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5720 * range. When the current element of one range is less than the other,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5721 * that element is copied and the iterator advanced. If an element is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5722 * contained in both ranges, the element from the first range is copied and
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5723 * both ranges advance. The output range may not overlap either input
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5724 * range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5725 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5726 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5727 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5728 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5729 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5730 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5731 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5732 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5733 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5734 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5735 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5736 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5737
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5738 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5739 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5740 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5741 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5742 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5743 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5744 _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5745 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5746 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5747 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5748 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5749
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5750 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5751 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5752 if (*__first1 < *__first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5753 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5754 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5755 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5756 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5757 else if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5758 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5759 *__result = *__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5760 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5761 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5762 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5763 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5764 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5765 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5766 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5767 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5768 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5769 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5770 return std::copy(__first2, __last2, std::copy(__first1, __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5771 __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5772 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5773
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5774 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5775 * @brief Return the union of two sorted ranges using a comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5776 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5777 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5778 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5779 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5780 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5781 * @param __comp The comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5782 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5783 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5784 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5785 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5786 * each range in order to the output range. Iterators increment for each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5787 * range. When the current element of one range is less than the other
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5788 * according to @p __comp, that element is copied and the iterator advanced.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5789 * If an equivalent element according to @p __comp is contained in both
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5790 * ranges, the element from the first range is copied and both ranges
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5791 * advance. The output range may not overlap either input range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5792 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5793 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5794 typename _OutputIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5795 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5796 set_union(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5797 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5798 _OutputIterator __result, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5799 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5800 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5801 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5802 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5803 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5804
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5805 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5806 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5807 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5808 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5809 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5810 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5811 _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5812 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5813 _ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5814 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5815 _ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5816 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5817 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5818
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5819 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5820 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5821 if (__comp(*__first1, *__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5822 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5823 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5824 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5825 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5826 else if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5827 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5828 *__result = *__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5829 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5830 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5831 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5832 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5833 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5834 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5835 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5836 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5837 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5838 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5839 return std::copy(__first2, __last2, std::copy(__first1, __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5840 __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5841 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5842
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5843 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5844 * @brief Return the intersection of two sorted ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5845 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5846 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5847 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5848 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5849 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5850 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5851 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5852 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5853 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5854 * both ranges in order to the output range. Iterators increment for each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5855 * range. When the current element of one range is less than the other,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5856 * that iterator advances. If an element is contained in both ranges, the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5857 * element from the first range is copied and both ranges advance. The
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5858 * output range may not overlap either input range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5859 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5860 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5861 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5862 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5863 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5864 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5865 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5866 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5867 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5868 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5869 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5870 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5871
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5872 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5873 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5874 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5875 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5876 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5877 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5878 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5879 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5880 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5881
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5882 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5883 if (*__first1 < *__first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5884 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5885 else if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5886 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5887 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5888 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5889 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5890 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5891 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5892 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5893 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5894 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5895 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5896
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5897 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5898 * @brief Return the intersection of two sorted ranges using comparison
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5899 * functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5900 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5901 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5902 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5903 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5904 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5905 * @param __comp The comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5906 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5907 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5908 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5909 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5910 * both ranges in order to the output range. Iterators increment for each
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5911 * range. When the current element of one range is less than the other
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5912 * according to @p __comp, that iterator advances. If an element is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5913 * contained in both ranges according to @p __comp, the element from the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5914 * first range is copied and both ranges advance. The output range may not
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5915 * overlap either input range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5916 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5917 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5918 typename _OutputIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5919 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5920 set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5921 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5922 _OutputIterator __result, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5923 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5924 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5925 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5926 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5927 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5928
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5929 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5930 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5931 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5932 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5933 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5934 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5935 _ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5936 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5937 _ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5938 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5939 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5940
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5941 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5942 if (__comp(*__first1, *__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5943 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5944 else if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5945 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5946 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5947 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5948 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5949 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5950 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5951 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5952 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5953 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5954 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5955
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5956 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5957 * @brief Return the difference of two sorted ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5958 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5959 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5960 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5961 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5962 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5963 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5964 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5965 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5966 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5967 * the first range but not the second in order to the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5968 * Iterators increment for each range. When the current element of the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5969 * first range is less than the second, that element is copied and the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5970 * iterator advances. If the current element of the second range is less,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5971 * the iterator advances, but no element is copied. If an element is
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5972 * contained in both ranges, no elements are copied and both ranges
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5973 * advance. The output range may not overlap either input range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5974 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5975 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5976 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5977 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5978 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5979 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5980 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5981 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5982 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5983 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5984 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5985 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5986
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5987 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5988 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5989 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5990 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5991 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5992 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5993 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5994 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5995 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5996
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5997 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5998 if (*__first1 < *__first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5999 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6000 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6001 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6002 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6003 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6004 else if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6005 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6006 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6007 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6008 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6009 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6010 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6011 return std::copy(__first1, __last1, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6012 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6013
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6014 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6015 * @brief Return the difference of two sorted ranges using comparison
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6016 * functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6017 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6018 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6019 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6020 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6021 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6022 * @param __comp The comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6023 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6024 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6025 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6026 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6027 * the first range but not the second in order to the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6028 * Iterators increment for each range. When the current element of the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6029 * first range is less than the second according to @p __comp, that element
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6030 * is copied and the iterator advances. If the current element of the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6031 * second range is less, no element is copied and the iterator advances.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6032 * If an element is contained in both ranges according to @p __comp, no
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6033 * elements are copied and both ranges advance. The output range may not
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6034 * overlap either input range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6035 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6036 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6037 typename _OutputIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6038 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6039 set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6040 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6041 _OutputIterator __result, _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6042 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6043 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6044 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6045 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6046 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6047
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6048 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6049 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6050 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6051 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6052 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6053 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6054 _ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6055 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6056 _ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6057 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6058 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6059
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6060 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6061 if (__comp(*__first1, *__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6062 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6063 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6064 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6065 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6066 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6067 else if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6068 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6069 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6070 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6071 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6072 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6073 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6074 return std::copy(__first1, __last1, __result);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6075 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6076
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6077 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6078 * @brief Return the symmetric difference of two sorted ranges.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6079 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6080 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6081 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6082 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6083 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6084 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6085 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6086 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6087 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6088 * one range but not the other in order to the output range. Iterators
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6089 * increment for each range. When the current element of one range is less
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6090 * than the other, that element is copied and the iterator advances. If an
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6091 * element is contained in both ranges, no elements are copied and both
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6092 * ranges advance. The output range may not overlap either input range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6093 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6094 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6095 typename _OutputIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6096 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6097 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6098 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6099 _OutputIterator __result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6100 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6101 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6102 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6103 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6104 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6105
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6106 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6107 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6108 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6109 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6110 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6111 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6112 _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6113 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6114 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6115 __glibcxx_requires_sorted_set(__first1, __last1, __first2);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6116 __glibcxx_requires_sorted_set(__first2, __last2, __first1);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6117
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6118 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6119 if (*__first1 < *__first2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6120 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6121 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6122 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6123 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6124 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6125 else if (*__first2 < *__first1)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6126 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6127 *__result = *__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6128 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6129 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6130 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6131 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6132 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6133 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6134 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6135 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6136 return std::copy(__first2, __last2, std::copy(__first1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6137 __last1, __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6138 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6139
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6140 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6141 * @brief Return the symmetric difference of two sorted ranges using
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6142 * comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6143 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6144 * @param __first1 Start of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6145 * @param __last1 End of first range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6146 * @param __first2 Start of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6147 * @param __last2 End of second range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6148 * @param __comp The comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6149 * @return End of the output range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6150 * @ingroup set_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6151 *
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6152 * This operation iterates over both ranges, copying elements present in
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6153 * one range but not the other in order to the output range. Iterators
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6154 * increment for each range. When the current element of one range is less
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6155 * than the other according to @p comp, that element is copied and the
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6156 * iterator advances. If an element is contained in both ranges according
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6157 * to @p __comp, no elements are copied and both ranges advance. The output
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6158 * range may not overlap either input range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6159 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6160 template<typename _InputIterator1, typename _InputIterator2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6161 typename _OutputIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6162 _OutputIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6163 set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6164 _InputIterator2 __first2, _InputIterator2 __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6165 _OutputIterator __result,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6166 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6167 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6168 typedef typename iterator_traits<_InputIterator1>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6169 _ValueType1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6170 typedef typename iterator_traits<_InputIterator2>::value_type
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6171 _ValueType2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6172
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6173 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6174 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6175 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6176 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6177 _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6178 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6179 _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6180 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6181 _ValueType1, _ValueType2>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6182 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6183 _ValueType2, _ValueType1>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6184 __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6185 __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6186
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6187 while (__first1 != __last1 && __first2 != __last2)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6188 if (__comp(*__first1, *__first2))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6189 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6190 *__result = *__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6191 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6192 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6193 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6194 else if (__comp(*__first2, *__first1))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6195 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6196 *__result = *__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6197 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6198 ++__result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6199 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6200 else
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6201 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6202 ++__first1;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6203 ++__first2;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6204 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6205 return std::copy(__first2, __last2,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6206 std::copy(__first1, __last1, __result));
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6207 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6208
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6209
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6210 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6211 * @brief Return the minimum element in a range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6212 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6213 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6214 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6215 * @return Iterator referencing the first instance of the smallest value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6216 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6217 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6218 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6219 min_element(_ForwardIterator __first, _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6220 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6221 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6222 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6223 __glibcxx_function_requires(_LessThanComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6224 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6225 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6226
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6227 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6228 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6229 _ForwardIterator __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6230 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6231 if (*__first < *__result)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6232 __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6233 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6234 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6235
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6236 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6237 * @brief Return the minimum element in a range using comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6238 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6239 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6240 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6241 * @param __comp Comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6242 * @return Iterator referencing the first instance of the smallest value
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6243 * according to __comp.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6244 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6245 template<typename _ForwardIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6246 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6247 min_element(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6248 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6249 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6250 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6251 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6252 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6253 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6254 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6255 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6256
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6257 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6258 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6259 _ForwardIterator __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6260 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6261 if (__comp(*__first, *__result))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6262 __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6263 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6264 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6265
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6266 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6267 * @brief Return the maximum element in a range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6268 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6269 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6270 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6271 * @return Iterator referencing the first instance of the largest value.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6272 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6273 template<typename _ForwardIterator>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6274 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6275 max_element(_ForwardIterator __first, _ForwardIterator __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6276 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6277 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6278 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6279 __glibcxx_function_requires(_LessThanComparableConcept<
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6280 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6281 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6282
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6283 if (__first == __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6284 return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6285 _ForwardIterator __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6286 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6287 if (*__result < *__first)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6288 __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6289 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6290 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6291
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6292 /**
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6293 * @brief Return the maximum element in a range using comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6294 * @ingroup sorting_algorithms
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6295 * @param __first Start of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6296 * @param __last End of range.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6297 * @param __comp Comparison functor.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6298 * @return Iterator referencing the first instance of the largest value
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6299 * according to __comp.
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6300 */
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6301 template<typename _ForwardIterator, typename _Compare>
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6302 _ForwardIterator
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6303 max_element(_ForwardIterator __first, _ForwardIterator __last,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6304 _Compare __comp)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6305 {
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6306 // concept requirements
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6307 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6308 __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6309 typename iterator_traits<_ForwardIterator>::value_type,
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6310 typename iterator_traits<_ForwardIterator>::value_type>)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6311 __glibcxx_requires_valid_range(__first, __last);
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6312
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6313 if (__first == __last) return __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6314 _ForwardIterator __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6315 while (++__first != __last)
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6316 if (__comp(*__result, *__first))
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6317 __result = __first;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6318 return __result;
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6319 }
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6320
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6321 _GLIBCXX_END_NAMESPACE_ALGO
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6322 } // namespace std
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6323
0d660785098e work around GCC bug in stl_algo.h (nth_element and sort; bug #40436)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6324 #endif /* _STL_ALGO_H */