40#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
66 static std::size_t funcalls_;
81 static const char*
name () {
return "Less"; }
84 void operator= (
Less&);
93<
class T,
class InputIterator1,
class InputIterator2,
class Predicate>
98 const InputIterator1 &it1,
99 const InputIterator2 &it2,
103 const char*
const it1name =
type_name (it1, (
T*)0);
104 const char*
const it2name =
type_name (it2, (
T*)0);
105 const char*
const fname =
"lexicographical_compare";
106 const char*
const funname = Predicate::name ();
108 const std::size_t nsrc1 = std::strlen (src1);
109 const std::size_t nsrc2 = std::strlen (src2);
111 T*
const xsrc1 = T::from_char (src1, nsrc1);
112 T*
const xsrc2 = T::from_char (src2, nsrc2);
114 T*
const xsrc1_end = xsrc1 + nsrc1;
115 T*
const xsrc2_end = xsrc2 + nsrc2;
117 const InputIterator1 first1 =
make_iter (xsrc1, xsrc1, xsrc1_end, it1);
118 const InputIterator1 last1 =
make_iter (xsrc1_end, xsrc1, xsrc1_end, it1);
119 const InputIterator2 first2 =
make_iter (xsrc2, xsrc2, xsrc2_end, it2);
120 const InputIterator2 last2 =
make_iter (xsrc2_end, xsrc2, xsrc2_end, it2);
124 const std::size_t last_n_op_lt = T::n_total_op_lt_;
126 const bool result = ppred ?
127 std::lexicographical_compare (first1, last1, first2, last2, pred)
128 : std::lexicographical_compare (first1, last1, first2, last2);
135 "line %d: %s<%s, %s%{?}, %s%{;}> (\"%s\", \"%s\", ...) "
137 __LINE__, fname, it1name, it2name, 0 != ppred, funname,
140 const std::size_t n_ops_lt = ppred ?
141 Predicate::funcalls_ : T::n_total_op_lt_ - last_n_op_lt;
144 const std::size_t n_exp_ops = 2 * (nsrc1 < nsrc2 ? nsrc1 : nsrc2);
146 "line %d: %s<%s, %s%{?}, %s%{;}> (\"%s\", \"%s\", ...) "
147 "complexity: got %zu, expected no more than %zu",
148 __LINE__, fname, it1name, it2name, 0 != ppred, funname,
149 src1, src2, n_ops_lt, n_exp_ops);
156<
class T,
class InputIterator1,
class InputIterator2,
class Predicate>
158 const InputIterator2 &it2,
162 const char*
const it1name =
type_name (it1, (
T*)0);
163 const char*
const it2name =
type_name (it2, (
T*)0);
164 const char*
const fname =
"lexicographical_compare";
165 const char*
const funname = Predicate::name();
168 "std::%s(%s, %2$s, %s, %3$s%{?}, %s%{;})",
169 fname, it1name, it2name, 0 != ppred, funname);
171#define TEST(src1, src2, res) \
172 test_lex_compare (__LINE__, src1, src2, res, it1, it2, (T*)0, ppred)
174 TEST (
"",
"",
false);
175 TEST (
"a",
"",
false);
176 TEST (
"",
"a",
true);
177 TEST (
"a",
"a",
false);
179 TEST (
"aa",
"aa",
false);
180 TEST (
"aa",
"ab",
true);
181 TEST (
"ba",
"ab",
false);
182 TEST (
"ba",
"ba",
false);
183 TEST (
"ba",
"bc",
true);
185 TEST (
"a",
"abc",
true);
186 TEST (
"a",
"bcd",
true);
187 TEST (
"a",
"baed",
true);
189 TEST (
"abcde",
"abcdefghij",
true);
190 TEST (
"fghij",
"fghijabcde",
true);
191 TEST (
"fghij",
"abcdefghij",
false);
192 TEST (
"cabed",
"abcdeabcde",
false);
194 TEST (
"abcdefghij",
"abcdefghij",
false);
195 TEST (
"fghijfghij",
"abcdefghij",
false);
196 TEST (
"fghijabcde",
"abcdeabcde",
false);
198 TEST (
"abcdefghij",
"bacdfeghji",
true);
199 TEST (
"bacdefghij",
"bacdfeghji",
true);
200 TEST (
"bacdfeghij",
"bacdfeghji",
true);
201 TEST (
"bacdfeghja",
"bacdfeghji",
true);
214template <
class T,
class InputIterator1,
class Predicate>
225 rw_note (0, __FILE__, __LINE__,
"InputIterator test disabled");
232 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
239 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
246 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
253template <
class T,
class Predicate>
263 "template <class %s, class %s%{?}, class %s%{;}> "
264 "bool std::lexicographical_compare (%1$s, %1$s, %2$s, "
266 "InputIterator1",
"InputIterator2", ppred,
"Compare",
267 0 != ppred,
"Compare");
270 rw_note (0, __FILE__, __LINE__,
"InputIterator test disabled");
277 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
284 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
291 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
305 rw_note (0, __FILE__, __LINE__,
306 "std::lexicographical_compare predicate test disabled");
318int main (
int argc,
char *argv[])
320 return rw_test (argc, argv, __FILE__,
321 "lib.lex.comparison",
325 "|-no-InputIterator# "
326 "|-no-ForwardIterator# "
327 "|-no-BidirectionalIterator# "
328 "|-no-RandomAccessIterator#",
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define TEST(src1, src2, res)
void test_lex_compare(int line, const char *src1, const char *src2, bool res, const InputIterator1 &it1, const InputIterator2 &it2, const T *, const Predicate *ppred)
#define _RWSTD_NAMESPACE(name)
T * make_iter(T *cur, const T *, const T *, T *)
_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)