43#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
76 static std::size_t funcalls_;
91 static const char*
name () {
return "Less"; }
94 void operator= (
Less&);
101template <
class T,
class Predicate>
111 const RandIter it(0, 0, 0);
113 const char*
const itname =
"RandomAccessIterator";
114 const char*
const fname = stable ?
"stable_sort" :
"sort";
115 const char*
const funname = ppred ? Predicate::name() :
"operator<()";
120 const std::size_t
nsrc = src ? std::strlen (src) :
N;
122 T*
const xsrc = src ? T::from_char (src,
nsrc) :
new T[
nsrc];
124 T*
const xsrc_end = xsrc +
nsrc;
126 RandIter first =
make_iter (xsrc, xsrc, xsrc_end, it);
131 std::size_t last_n_op_lt = T::n_total_op_lt_;
132 std::size_t last_n_op_cpy = T::n_total_op_assign_ + T::n_total_copy_ctor_;
137 std::pair<UserClass*, std::ptrdiff_t> dummy;
139 dummy = std::_GET_TEMP_BUFFER (
T,
nsrc + 1);
141 "line %d: %s<%s%{?}, %s%{;}> (): "
142 "memory allocation failed for %zu elements",
143 __LINE__, fname, itname, ppred, funname,
nsrc);
147 std::stable_sort (first,
last, pred);
149 std::stable_sort (first,
last);
151 if (
alloc && dummy.first)
152 std::return_temporary_buffer (dummy.first);
156 std::sort (first,
last, pred);
158 std::sort (first,
last);
201 static const int cwidth =
sizeof (
T);
207 "line %d: %s<%s%{?}, %s%{;}> (\"%s\", ...) ==> "
208 "\"%{X=*.*}\" not sorted",
209 __LINE__, fname, itname, ppred, funname, src,
210 cwidth,
int (
nsrc), -1, xsrc);
214 "line %d: %s<%s%{?}, %s%{;}> (%zu, ...): "
216 __LINE__, fname, itname, ppred, funname,
nsrc);
222 const std::size_t n_ops =
223 ppred ? Predicate::funcalls_ : T::n_total_op_lt_ - last_n_op_lt;
226 success = 2 * n_ops <= exp_ops;
228 "line %d: %s<%s%{?}, %s%{;}> (): complexity for "
229 "length %zu is %zu, expected no more than %zu",
230 __LINE__, fname, itname, ppred, funname,
nsrc,
236 for ( ;
j <
N;
j++) {
237 if (xsrc[
j - 1].data_.val_ == xsrc[
j].data_.val_)
238 success = xsrc[
j - 1].origin_ < xsrc[
j].origin_;
249 "line %d: %s<%s%{?}, %s%{;}> (\"%s\", ...) ==> "
250 "\"%{X=*.*}\" relative order is broken at %zu: "
251 "got ids %zu and %zu for values %#c and %#c",
252 __LINE__, fname, itname, ppred, funname, src,
253 cwidth,
int (
nsrc), -1, xsrc,
j, xsrc[
j - 1].origin_,
254 xsrc[
j].origin_, xsrc[
j - 1].data_.val_,
259 "line %d: %s<%s%{?}, %s%{;}> (): relative order "
260 "is broken for %zu at %zu: got ids %zu and %zu "
261 "for values %d and %d",
262 __LINE__, fname, itname, ppred, funname,
263 nsrc,
j, xsrc[
j - 1].origin_, xsrc[
j].origin_,
264 xsrc[
j - 1].data_.val_, xsrc[
j].data_.val_);
281template <
class T,
class Predicate>
289 "template <class %s%{?}, class %s%{;}> "
290 "void std::%{?}stable_%{;}sort (%1$s, %1$s%{?}, %3$s%{;})"
291 "%{?} with memory allocation%{;}",
292 "RandomAccessIterator", ppred,
"StrictWeakComp",
293 stable, ppred, stable &&
alloc);
295 const char*
const itname =
"RandomAccessIterator";
296 const char*
const fname = stable ?
"stable_sort" :
"sort";
297 const char*
const funname = ppred ? Predicate::name() :
"operator<()";
300 "std::%s (%s, %2$s%{?}, %s%{;})",
301 fname, itname, ppred, funname);
304 test_sort (__LINE__, src, 0, (T*)0, ppred, stable, alloc)
342 "std::%s (%s, %2$s%{?}, %s%{;}) complexity test disabled",
343 fname, itname, ppred, funname);
347 "std::%s (%s, %2$s%{?}, %s%{;}): complexity test",
348 fname, itname, ppred, funname);
350 for (std::size_t
i = 1;
i <
N;
i++)
366 rw_note (0, __FILE__, __LINE__,
367 "std::%{?}stable_%{;}sort predicate test disabled",
384 rw_note (0, __FILE__, __LINE__,
"std::sort test disabled");
391 rw_note (0, __FILE__, __LINE__,
"std::stable_sort test disabled");
405int main (
int argc,
char *argv[])
407 return rw_test (argc, argv, __FILE__,
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
int rw_opt_no_stable_sort
void test_sort(int line, const char *src, const std::size_t N, const T *, const Predicate *ppred, bool stable, bool alloc)
#define _RWSTD_UNUSED(arg)
#define _RWSTD_NAMESPACE(name)
T * make_iter(T *cur, const T *, const T *, T *)
_TEST_EXPORT unsigned ilog2(_RWSTD_SIZE_T)
bool is_sorted_lt(InputIterator first, InputIterator last)
_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 const char * name()
static conv_to_bool make(bool val)