40#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
79 static const char*
name () {
return "StrictWeakLess"; }
91template <
class T,
class Predicate>
95 const std::size_t nth,
103 const RandIter it(0, 0, 0);
105 const char*
const itname =
type_name (it, (
T*)0);
106 const char*
const fname =
"nth_element";
107 const char*
const funname = Predicate::name();
109 const std::size_t
nsrc = src ? std::strlen (src) :
N;
112 T*
const xsrc = src ? T::from_char (src,
nsrc) :
new T[
nsrc];
114 T*
const xsrc_end = xsrc +
nsrc;
117 const RandIter first =
make_iter (xsrc, xsrc, xsrc_end, it);
118 const RandIter nth_it =
make_iter (xsrc + nth, xsrc, xsrc_end, it);
119 const RandIter
last =
make_iter (xsrc_end, xsrc, xsrc_end, it);
123 const std::size_t last_n_op_lt = T::n_total_op_lt_;
126 std::nth_element (first, nth_it,
last, pred);
128 std::nth_element (first, nth_it,
last);
135 for (
i = 0;
i < nth;
i++) {
137 success = xsrc[
i].data_.val_ <= xsrc[
j].data_.val_;
147 i =
i < nth ?
i : nth - 1;
152 "line %d: %s<%s%{?}, %s%{;}>(\"%s\", %zu, ...) ==> "
153 "\"%{X=*.*}\", got %#c at %zu !< %#c at %zu",
154 __LINE__, fname, itname, ppred, funname, src, nth,
155 int (
sizeof (*xsrc)),
int (
nsrc), -1, xsrc,
156 xsrc[
i].data_.val_,
i, xsrc[
j].data_.val_,
j);
160 "line %d: %s<%s%{?}, %s%{;}>(%zu, %zu, ...) "
161 "got %d at %zu !< %d at %zu",
162 __LINE__, fname, itname, ppred, funname,
N, nth,
163 xsrc[
i].data_.val_,
i, xsrc[
j].data_.val_,
j);
170 ppred ? Predicate::funcalls_ : T::n_total_op_lt_ - last_n_op_lt;
171 std::size_t exp_ops = 8 *
nsrc;
173 success = n_ops <= exp_ops;
176 "line %d: %s<%s%{?}, %s%{;}>(%{?}\"%s\"%{;}%{?}%zu%{;}, "
177 "%zu, ...): complexity: got %zu, expected no more than %zu",
178 __LINE__, fname, itname, ppred, funname,
179 src, src, !src,
N, nth, n_ops, exp_ops);
192template <
class T,
class Predicate>
198 const char*
const itname =
type_name (RandIter (0, 0, 0), (
T*)0);
199 const char*
const fname =
"nth_element";
200 const char*
const funname = Predicate::name();
203 "std::%s (%s, %2$s, %2$s%{?}, %s%{;})",
204 fname, itname, ppred, funname);
206#define TEST(src, nth) \
207 test_nth_element (__LINE__, src, 0, nth, (T*)0, ppred)
213 TEST (
"jihgfedcba", 0);
214 TEST (
"jihgfedcba", 1);
215 TEST (
"jihgfedcba", 2);
216 TEST (
"jihgfedcba", 3);
217 TEST (
"jihgfedcba", 4);
218 TEST (
"jihgfedcba", 5);
219 TEST (
"jihgfedcba", 6);
220 TEST (
"jihgfedcba", 7);
221 TEST (
"jihgfedcba", 8);
222 TEST (
"jihgfedcba", 9);
224 TEST (
"abcdefghij", 0);
225 TEST (
"abcdefghij", 1);
226 TEST (
"abcdefghij", 2);
227 TEST (
"abcdefghij", 3);
228 TEST (
"abcdefghij", 4);
229 TEST (
"abcdefghij", 5);
230 TEST (
"abcdefghij", 6);
231 TEST (
"abcdefghij", 7);
232 TEST (
"abcdefghij", 8);
233 TEST (
"abcdefghij", 9);
235 TEST (
"jijgfgdcda", 5);
236 TEST (
"jihifefcbc", 5);
237 TEST (
"jiigffdcca", 5);
238 TEST (
"jihhfeecbb", 5);
240 TEST (
"cbbbbbbbba", 5);
241 TEST (
"ccbbbbbbaa", 5);
243 TEST (
"abadedghgj", 5);
244 TEST (
"abcbefehih", 5);
245 TEST (
"abbdeeghhj", 5);
246 TEST (
"abcceffhii", 5);
248 TEST (
"abbbbbbbbc", 5);
249 TEST (
"aabbbbbbcc", 5);
255 "std::%s (%s, %2$s, %2$s%{?}, %s%{;}): "
256 "complexity test disabled",
257 fname, itname, ppred, funname);
261 "std::%s (%s, %2$s, %2$s%{?}, %s%{;}): complexity test",
262 fname, itname, ppred, funname);
265 for (std::size_t
i = 1;
i <
N;
i++)
275 "template <class %s> "
276 "void std::nth_element (%1$s, %1$s, %1$s)",
277 "RandomAccessIterator");
282 rw_note (0, __FILE__, __LINE__,
283 "std::nth_element predicate test disabled");
287 "template <class %s, class %s> "
288 "void std::nth_element (%1$s, %1$s, %1$s, %2$s)",
289 "RandomAccessIterator",
"StrictWeakLess");
301int main (
int argc,
char *argv[])
303 return rw_test (argc, argv, __FILE__,
304 "lib.alg.nth_element",
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void test_nth_element(int line, const char *src, const std::size_t N, const std::size_t nth, const T *, const Predicate *ppred)
#define _RWSTD_UNUSED(arg)
#define _RWSTD_NAMESPACE(name)
T * make_iter(T *cur, const T *, const T *, T *)
_TEST_EXPORT int gen_rnd()
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
static std::size_t funcalls_
static const char * name()
static conv_to_bool make(bool val)