22
22
#define _TESTLIB_H_
23
23
24
24
/*
25
- * Copyright (c) 2005-2022
25
+ * Copyright (c) 2005-2023
26
26
*/
27
27
28
- #define VERSION " 0.9.40-SNAPSHOT "
28
+ #define VERSION " 0.9.41-alpha "
29
29
30
30
/*
31
31
* Mike Mirzayanov
63
63
*/
64
64
65
65
const char *latestFeatures[] = {
66
+ " Use setAppesModeEncoding to change xml encoding from windows-1251 to other" ,
67
+ " rnd.any/wany use distance/advance instead of -/+: now they support sets/multisets" ,
68
+ " Use syntax `int t = inf.readInt(1, 3, \" ~t\" );` to skip the lower bound check. Tildes can be used on either side or both: ~t, t~, ~t~" ,
69
+ " Supported EJUDGE support in registerTestlibCmd" ,
66
70
" Supported '--testMarkupFileName fn' and '--testCase tc/--testCaseFileName fn' for validators" ,
67
71
" Added opt defaults via opt<T>(key/index, default_val); check unused opts when using has_opt or default opt (turn off this check with suppressEnsureNoUnusedOpt())." ,
68
72
" For checker added --group and --testset command line params (like for validator), use checker.group() or checker.testset() to get values" ,
@@ -343,25 +347,40 @@ void unsetTestCase() {
343
347
NORETURN static void __testlib_fail (const std::string &message);
344
348
345
349
template <typename T>
350
+ #ifdef __GNUC__
351
+ __attribute__ ((const ))
352
+ #endif
346
353
static inline T __testlib_abs (const T &x) {
347
354
return x > 0 ? x : -x;
348
355
}
349
356
350
357
template <typename T>
358
+ #ifdef __GNUC__
359
+ __attribute__ ((const ))
360
+ #endif
351
361
static inline T __testlib_min (const T &a, const T &b) {
352
362
return a < b ? a : b;
353
363
}
354
364
355
365
template <typename T>
366
+ #ifdef __GNUC__
367
+ __attribute__ ((const ))
368
+ #endif
356
369
static inline T __testlib_max (const T &a, const T &b) {
357
370
return a > b ? a : b;
358
371
}
359
372
360
373
template <typename T>
374
+ #ifdef __GNUC__
375
+ __attribute__ ((const ))
376
+ #endif
361
377
static inline T __testlib_crop (T value, T a, T b) {
362
378
return __testlib_min (__testlib_max (value, a), --b);
363
379
}
364
380
381
+ #ifdef __GNUC__
382
+ __attribute__ ((const ))
383
+ #endif
365
384
static inline double __testlib_crop (double value, double a, double b) {
366
385
value = __testlib_min (__testlib_max (value, a), b);
367
386
if (value >= b)
@@ -378,6 +397,9 @@ static bool __testlib_prelimIsNaN(double r) {
378
397
#endif
379
398
}
380
399
400
+ #ifdef __GNUC__
401
+ __attribute__ ((const ))
402
+ #endif
381
403
static std::string removeDoubleTrailingZeroes (std::string value) {
382
404
while (!value.empty () && value[value.length () - 1 ] == ' 0' && value.find (' .' ) != std::string::npos)
383
405
value = value.substr (0 , value.length () - 1 );
@@ -387,13 +409,19 @@ static std::string removeDoubleTrailingZeroes(std::string value) {
387
409
return value;
388
410
}
389
411
412
+ #ifdef __GNUC__
413
+ __attribute__ ((const ))
414
+ #endif
390
415
inline std::string upperCase (std::string s) {
391
416
for (size_t i = 0 ; i < s.length (); i++)
392
417
if (' a' <= s[i] && s[i] <= ' z' )
393
418
s[i] = char (s[i] - ' a' + ' A' );
394
419
return s;
395
420
}
396
421
422
+ #ifdef __GNUC__
423
+ __attribute__ ((const ))
424
+ #endif
397
425
inline std::string lowerCase (std::string s) {
398
426
for (size_t i = 0 ; i < s.length (); i++)
399
427
if (' A' <= s[i] && s[i] <= ' Z' )
@@ -414,6 +442,9 @@ std::string format(const std::string fmt, ...) {
414
442
return result;
415
443
}
416
444
445
+ #ifdef __GNUC__
446
+ __attribute__ ((const ))
447
+ #endif
417
448
static std::string __testlib_part (const std::string &s);
418
449
419
450
static bool __testlib_isNaN (double r) {
@@ -532,6 +563,9 @@ static void __testlib_set_binary(std::FILE *file) {
532
563
533
564
#if __cplusplus > 199711L || defined(_MSC_VER)
534
565
template <typename T>
566
+ #ifdef __GNUC__
567
+ __attribute__ ((const ))
568
+ #endif
535
569
static std::string vtos (const T &t, std::true_type) {
536
570
if (t == 0 )
537
571
return " 0" ;
@@ -3297,6 +3331,9 @@ void InStream::readTokenTo(std::string &result) {
3297
3331
readWordTo (result);
3298
3332
}
3299
3333
3334
+ #ifdef __GNUC__
3335
+ __attribute__ ((const ))
3336
+ #endif
3300
3337
static std::string __testlib_part (const std::string &s) {
3301
3338
std::string t;
3302
3339
for (size_t i = 0 ; i < s.length (); i++)
@@ -4824,10 +4861,16 @@ void startTest(int test) {
4824
4861
__testlib_fail (" Unable to write file '" + testFileName + " '" );
4825
4862
}
4826
4863
4864
+ #ifdef __GNUC__
4865
+ __attribute__ ((const ))
4866
+ #endif
4827
4867
inline std::string compress (const std::string &s) {
4828
4868
return __testlib_part (s);
4829
4869
}
4830
4870
4871
+ #ifdef __GNUC__
4872
+ __attribute__ ((const ))
4873
+ #endif
4831
4874
inline std::string englishEnding (int x) {
4832
4875
x %= 100 ;
4833
4876
if (x / 10 == 1 )
@@ -4842,6 +4885,9 @@ inline std::string englishEnding(int x) {
4842
4885
}
4843
4886
4844
4887
template <typename _ForwardIterator, typename _Separator>
4888
+ #ifdef __GNUC__
4889
+ __attribute__ ((const ))
4890
+ #endif
4845
4891
std::string join (_ForwardIterator first, _ForwardIterator last, _Separator separator) {
4846
4892
std::stringstream ss;
4847
4893
bool repeated = false ;
@@ -4856,16 +4902,25 @@ std::string join(_ForwardIterator first, _ForwardIterator last, _Separator separ
4856
4902
}
4857
4903
4858
4904
template <typename _ForwardIterator>
4905
+ #ifdef __GNUC__
4906
+ __attribute__ ((const ))
4907
+ #endif
4859
4908
std::string join (_ForwardIterator first, _ForwardIterator last) {
4860
4909
return join (first, last, ' ' );
4861
4910
}
4862
4911
4863
4912
template <typename _Collection, typename _Separator>
4913
+ #ifdef __GNUC__
4914
+ __attribute__ ((const ))
4915
+ #endif
4864
4916
std::string join (const _Collection &collection, _Separator separator) {
4865
4917
return join (collection.begin (), collection.end (), separator);
4866
4918
}
4867
4919
4868
4920
template <typename _Collection>
4921
+ #ifdef __GNUC__
4922
+ __attribute__ ((const ))
4923
+ #endif
4869
4924
std::string join (const _Collection &collection) {
4870
4925
return join (collection, ' ' );
4871
4926
}
@@ -4874,6 +4929,9 @@ std::string join(const _Collection &collection) {
4874
4929
* Splits string s by character separator returning exactly k+1 items,
4875
4930
* where k is the number of separator occurrences.
4876
4931
*/
4932
+ #ifdef __GNUC__
4933
+ __attribute__ ((const ))
4934
+ #endif
4877
4935
std::vector<std::string> split (const std::string &s, char separator) {
4878
4936
std::vector<std::string> result;
4879
4937
std::string item;
@@ -4891,6 +4949,9 @@ std::vector<std::string> split(const std::string &s, char separator) {
4891
4949
* Splits string s by character separators returning exactly k+1 items,
4892
4950
* where k is the number of separator occurrences.
4893
4951
*/
4952
+ #ifdef __GNUC__
4953
+ __attribute__ ((const ))
4954
+ #endif
4894
4955
std::vector<std::string> split (const std::string &s, const std::string &separators) {
4895
4956
if (separators.empty ())
4896
4957
return std::vector<std::string>(1 , s);
@@ -4914,6 +4975,9 @@ std::vector<std::string> split(const std::string &s, const std::string &separato
4914
4975
/* *
4915
4976
* Splits string s by character separator returning non-empty items.
4916
4977
*/
4978
+ #ifdef __GNUC__
4979
+ __attribute__ ((const ))
4980
+ #endif
4917
4981
std::vector<std::string> tokenize (const std::string &s, char separator) {
4918
4982
std::vector<std::string> result;
4919
4983
std::string item;
@@ -4932,6 +4996,9 @@ std::vector<std::string> tokenize(const std::string &s, char separator) {
4932
4996
/* *
4933
4997
* Splits string s by character separators returning non-empty items.
4934
4998
*/
4999
+ #ifdef __GNUC__
5000
+ __attribute__ ((const ))
5001
+ #endif
4935
5002
std::vector<std::string> tokenize (const std::string &s, const std::string &separators) {
4936
5003
if (separators.empty ())
4937
5004
return std::vector<std::string>(1 , s);
0 commit comments