30#if defined (_MSC_VER) && _MSC_VER <= 1300
31# define _RWSTD_NO_EXPLICIT_INSTANTIATION
45#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
119 static const char*
name () {
return "Less"; }
122 void operator= (
Less&);
133 std::size_t parent = 0;
134 for (std::size_t child = 1; child <
len; ++child) {
136 if (seq [parent].data_.val_ < seq [child].data_.val_)
139 if ((child & 1) == 0)
149template <
class T,
class Predicate>
154 const std::size_t finx)
156 static const char*
const fnames[] = {
157 "make_heap",
"push_heap",
"pop_heap",
"sort_heap"
161 RandIter rand_iter (0, 0, 0);
163 const char*
const itname =
type_name (rand_iter, (
T*)0);
164 const char*
const fname =
fnames[finx];
165 const char*
const funname = Predicate::name();
167 const std::size_t
nsrc = std::strlen (src);
169 T*
const xsrc = T::from_char (src,
nsrc);
170 T*
const xsrc_end = xsrc +
nsrc;
172 int val = xsrc[0].data_.val_;
174 const RandIter first =
make_iter (xsrc, xsrc, xsrc_end, rand_iter);
175 const RandIter
last =
make_iter (xsrc_end, xsrc, xsrc_end, rand_iter);
179 const std::size_t last_n_op_lt = T::n_total_op_lt_;
182#define HEAP_OP(opname) \
183 if (ppred) opname (first, last, pred); else opname (first, last)
189 case 0:
HEAP_OP (std::make_heap); ops = 3 *
nsrc;
break;
195 const std::size_t n_ops_lt = ppred ?
196 Predicate::funcalls_ : T::n_total_op_lt_ - last_n_op_lt;
198 const std::size_t
len = 2 != finx ?
nsrc :
nsrc - 1;
199 static const int cwidth =
sizeof (
T);
205 "line %d std::%s <%s%{?}, %s%{;}> (\"%s\", ...) ==> "
206 "\"%{X=*.*}\", last is %#c, expected %#c",
207 __LINE__, fname, itname, ppred, funname, src,
208 cwidth, int (
nsrc), -1, xsrc,
209 xsrc [
nsrc - 1].data_.val_,
val);
215 "line %d std::%s <%s%{?}, %s%{;}> (\"%s\", ...) ==> "
216 "\"%{X=*.*}\" is not sorted",
217 __LINE__, fname, itname, ppred, funname, src,
218 cwidth,
int (
nsrc), -1, xsrc);
224 "line %d std::%s <%s%{?}, %s%{;}> (\"%s\", ...) ==> "
225 "\"%{X=*.*}\" is not a heap",
226 __LINE__, fname, itname, ppred, funname, src,
227 cwidth,
int (
len), -1, xsrc);
233 "line %d std::%s <%s%{?}, %s%{;}> (\"%s\", ...) ==> "
234 "\"%{X=*.*}\" complexity: got %zu invocations of %s, "
235 "expected no more %zu",
236 __LINE__, fname, itname, ppred, funname, src,
237 cwidth,
int (
nsrc), -1, xsrc, n_ops_lt,
238 ppred ?
"predicate" :
"operator< ()", ops);
245template <
class T,
class Predicate>
250 "std::make_heap (%s, %1$s%{?}, %s%{;})",
251 "RandomAccessIterator", 0 != ppred, Predicate::name ());
254 test_heap_operation (__LINE__, src, (T*)0, ppred, 0)
285template <
class T,
class Predicate>
290 "std::push_heap (%s, %1$s%{?}, %s%{;})",
291 "RandomAccessIterator", 0 != ppred, Predicate::name ());
294 test_heap_operation (__LINE__, src, (T*)0, ppred, 1)
327template <
class T,
class Predicate>
332 "std::pop_heap (%s, %1$s%{?}, %s%{;})",
333 "RandomAccessIterator", 0 != ppred, Predicate::name ());
336 test_heap_operation (__LINE__, src, (T*)0, ppred, 2)
364template <
class T,
class Predicate>
369 "std::sort_heap (%s, %1$s%{?}, %s%{;})",
370 "RandomAccessIterator", 0 != ppred, Predicate::name());
373 test_heap_operation (__LINE__, src, (T*)0, ppred, 3)
409template <
class T,
class Predicate>
414 rw_note (0, __FILE__, __LINE__,
415 "std::make_heap test disabled");
422 rw_note (0, __FILE__, __LINE__,
423 "std::push_heap test disabled");
430 rw_note (0, __FILE__, __LINE__,
431 "std::pop_heap test disabled");
438 rw_note (0, __FILE__, __LINE__,
439 "std::sort_heap test disabled");
453 rw_note (0, __FILE__, __LINE__,
454 "heap operations predicate test disabled");
466int main (
int argc,
char *argv[])
468 return rw_test (argc, argv, __FILE__,
469 "lib.alg.heap.operations",
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void test_heap_operation(int line, const char *src, const T *, const Predicate *ppred, const std::size_t finx)
void test_sort_heap(const T *, const Predicate *ppred)
void test_pop_heap(const T *, const Predicate *ppred)
void test_push_heap(const T *, const Predicate *ppred)
bool is_heap(const T *seq, const std::size_t len)
void test_heap_operations(const T *, const Predicate *ppred)
void test_make_heap(const T *, const Predicate *ppred)
const char *const fnames[]
#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 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 std::size_t funcalls_
static conv_to_bool make(bool val)