aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_stringfmt01.cpp
blob: 279d9bb5cce9f6cd487438d2122f9eb2dc836bee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/**
 * Copyright the Collabora Online contributors.
 * Copyright Gothel Software e.K.
 *
 * ***
 *
 * SPDX-License-Identifier: MPL-2.0
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * ***
 *
 * SPDX-License-Identifier: MIT
 *
 * This Source Code Form is subject to the terms of the MIT License
 * If a copy of the MIT was not distributed with this
 * file, You can obtain one at https://opensource.org/license/mit/.
 *
 */
#include <sys/types.h>
#include <cassert>
#include <cinttypes>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string_view>
#include <type_traits>

#include <jau/cpp_lang_util.hpp>
#include <jau/cpp_pragma.hpp>
#include <jau/float_types.hpp>
#include <jau/int_types.hpp>
#include <jau/string_cfmt.hpp>
#include <jau/string_util.hpp>
#include <jau/test/catch2_ext.hpp>
#include <jau/type_traits_queries.hpp>

#include "string_cfmt2.hpp"

#ifdef HAS_STD_FORMAT
    #include <format>
#endif

using namespace std::literals;

using namespace jau::float_literals;

using namespace jau::int_literals;

template <typename... Args>
constexpr std::string format_string000(const std::size_t maxStrLen, const std::string_view format, const Args &...args) {
    std::string str;
    str.reserve(maxStrLen + 1);  // incl. EOS
    str.resize(maxStrLen);       // excl. EOS

    // -Wformat=2 -> -Wformat -Wformat-nonliteral -Wformat-security -Wformat-y2k
    // -Wformat=2 -Wformat-overflow=2 -Wformat-signedness
    PRAGMA_DISABLE_WARNING_PUSH
    PRAGMA_DISABLE_WARNING_FORMAT_NONLITERAL
    const size_t nchars = std::snprintf(&str[0], maxStrLen + 1, format.data(), args...);
    PRAGMA_DISABLE_WARNING_POP
    if( nchars < maxStrLen + 1 ) {
        str.resize(nchars);
        str.shrink_to_fit();
    }  // else truncated w/ nchars > MaxStrLen
    return str;
}

std::string format_000a_vsnprintf(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    size_t nchars;
    std::string str;
    {
        const size_t bsz = 1024;  // including EOS
        str.reserve(bsz);         // incl. EOS
        str.resize(bsz - 1);      // excl. EOS

        nchars = std::snprintf(&str[0], bsz,
                               "format_000a: %f, %f, %zu, %" PRIu64 ", %d\n",
                               fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);

        if( nchars < bsz ) {
            str.resize(nchars);
            str.shrink_to_fit();
            return str;
        }
    }
    str.clear();  // error
    return str;
}

std::string format_010a_vsnprintf(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    return jau::format_string("format_010a: %f, %f, %zu, %" PRIu64 ", %d\n",
                              fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);
}

constexpr std::string format_020a_tsnprintf(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    return jau::format_string_v(1023, "format_020a: %f, %f, %zu, %" PRIu64 ", %d\n",
                                fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);
}

std::string format_030a_strstream(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    std::ostringstream ss1;
    ss1 << "format_030a: "
        << fa + 1.0_f32 << ", "
        << fb + 1.0_f32 << ", "
        << sz1 + 1 << ", "
        << a_u64 + 1_u64 << ", "
        << i + 1 << "\n";
    return ss1.str();
}

#ifdef HAS_STD_FORMAT
std::string format_040a_stdformat(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    return std::format("format_040a: {0}, {1}, {3}, {4}, {5}\n",
                       fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);
}
#endif

std::string format_000b_vsnprintf(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    size_t nchars;
    std::string str;
    {
        const size_t bsz = 1024;  // including EOS
        str.reserve(bsz);         // incl. EOS
        str.resize(bsz - 1);      // excl. EOS

        nchars = std::snprintf(&str[0], bsz,
                               "format_000b: %.2f, %2.2f, %zu, %" PRIu64 ", %03d\n",
                               fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);

        if( nchars < bsz ) {
            str.resize(nchars);
            str.shrink_to_fit();
            return str;
        }
    }
    str.clear();  // error
    return str;
}
std::string format_010b_vsnprintf(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    return jau::format_string("format_010b: %.2f, %2.2f, %zu, %" PRIu64 ", %03d\n",
                              fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);
}

std::string format_020b_tsnprintf(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    return jau::format_string_v(1023, "format_020b: %.2f, %2.2f, %zu, %" PRIu64 ", %03d\n",
                                fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);
}

std::string format_030b_strstream(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    std::ostringstream ss1;
    ss1.precision(3);
    ss1 << "format_030b: "
        << fa + 1.0_f32 << ", ";
    ss1.width(3);
    ss1 << fb + 1.0_f32 << ", "
        << sz1 + 1 << ", "
        << a_u64 + 1_u64 << ", ";
    ss1.width(3);
    ss1 << i + 1 << "\n";
    return ss1.str();
}

#ifdef HAS_STD_FORMAT
std::string format_040b_stdformat(float fa, float fb, size_t sz1, uint64_t a_u64, int i) {
    return std::format("format_040b: {0:.2f}, {1:2.2f}, {3}, {4}, {5:03d}\n",
                       fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, i + 1);
}
#endif

template <typename Func>
size_t test_format(const Func func, bool output) {
    constexpr float fa = 1.1f, fb = 2.2f;
    constexpr size_t sz1 = 1;
    constexpr uint64_t sz2 = 2;
    constexpr int i = 3;

    const std::string s = func(fa, fb, sz1, sz2, i);
    volatile size_t l = s.length();
    if( output ) {
        std::cout << s;
    }
    REQUIRE(0 < l);
    REQUIRE(l < 1024);
    return l;
}

void format_0a() {
    test_format(format_000a_vsnprintf, true);
    test_format(format_010a_vsnprintf, true);
    test_format(format_020a_tsnprintf, true);
    test_format(format_030a_strstream, true);

#ifdef HAS_STD_FORMAT
    test_format(format_040a_stdformat, true);
#endif
}
void format_0b() {
    test_format(format_000b_vsnprintf, true);
    test_format(format_010b_vsnprintf, true);
    test_format(format_020b_tsnprintf, true);
    test_format(format_030b_strstream, true);

#ifdef HAS_STD_FORMAT
    test_format(format_040b_stdformat, true);
#endif
}

template <typename... Args>
constexpr std::string format_string_static2(const std::string_view fmt, const Args &...) {
    // constexpr const std::string format2(format);
    // constexpr const bool b = jau::cfmt::check2<Args...>("Haus"sv);
    constexpr const bool b = jau::cfmt::check3<Args...>(fmt);
    static_assert( b );
    (void)b;
    return ""; // jau::format_string_v(1024, format, args...);
}


template <typename... Targs>
constexpr jau::cfmt2::PResult check(const std::string_view fmt, const Targs &...) noexcept {
    return jau::cfmt2::impl::checkRec<Targs...>( jau::cfmt2::PResult(fmt) );
}

template <typename... Targs>
constexpr std::string format_string_static3(const std::string_view format, const Targs &...args) {
    // constexpr const jau::cfmt2::PResult ctx2 = jau::cfmt2::impl::checkRec<Targs...>( jau::cfmt2::PResult(format) );
    // static_assert( 0 <= jau::cfmt2::impl::checkRec<Targs...>( jau::cfmt2::PResult(format)).argCount() );
    if( 0 <= jau::cfmt2::impl::checkRec<Targs...>( jau::cfmt2::PResult(format)).argCount() ) {
        return jau::format_string_v(1024, format, args...);
    } else {
        return "";
    }
}


TEST_CASE("jau::cfmt_00", "[jau][std::string][jau::cfmt]") {
    char buf[1024];
    constexpr float fa = 1.123456f, fb = 2.2f;
    constexpr size_t sz1 = 1;
    constexpr int64_t sz2 = 2;
    constexpr int i = 3;
    const float *pf = &fa;

    {
        constexpr jau::cfmt2::PResult pr = jau::cfmt2::checkR("lala %d", 2);
        std::cerr << "XXX: " << __LINE__ << ": " << pr << std::endl;
        static_assert( 0 <= pr.argCount() );
    }
    {   // 'format_check: %.2f, %2.2f, %zu, %lu, %03d'
        constexpr  jau::cfmt2::PResult pc = jau::cfmt2::checkR("format_check: %.2f, %2.2f, %zu, %" PRIu64 ", %03d\n",
                                                               fa, fb, sz1, sz2, i);
        std::cerr << "XXX: " << __LINE__ << ": " << pc << std::endl;
        // static_assert( 5 == pc.argCount() );
        REQUIRE(5 == pc.argCount());
    }
    {
        constexpr jau::cfmt2::PResult pr = jau::cfmt2::checkR("lala %d - end", 2);
        std::cerr << "XXX: " << __LINE__ << ": " << pr << std::endl;
        // static_assert( 0 <= pr.argCount() );
        REQUIRE(0 <= pr.argCount());
    }
    {
        constexpr const bool b1 = jau::cfmt::check("lala %d", 2);
        static_assert( b1 );

        constexpr const bool b2 = jau::cfmt::check2<int>("lala %d");
        static_assert( b2 );

        // constexpr jau::cfmt2::PResult pr1 = check(fmt3, 2);
        constexpr jau::cfmt2::PResult pr1 = check("Hello %d", 2);
        std::cerr << "XXX: " << __LINE__ << ": " << pr1 << std::endl;
        static_assert( 0 <= pr1.argCount() );

        std::string s3 = format_string_static3("Hello %d", 2);
        std::cerr << "XXX: " << __LINE__ << ": " << s3 << std::endl;
        REQUIRE( s3.length() > 0 );

    // constexpr const std::string f2 = "Hello %d"s;
    // constexpr const std::string_view f2v = "Hello %d"sv;
    // format_string_static2(f2v, (int)2);
    // constexpr const std::string_view f3 = "Hello %d"sv;
    // constexpr const char f3[] = "Hello %d";
    // format_string_static2("Hello %d"sv, (int)2);
    }
    {
        static_assert(false == std::is_signed_v<const float*>);
        static_assert(false == std::is_unsigned_v<const float*>);

        static_assert(true == std::is_signed_v<float>);
        static_assert(false == std::is_unsigned_v<float>);
    }
    {
        using E = int;
        using T = unsigned int;
        // using U = std::conditional_t<std::is_unsigned_v<T>, std::make_signed_t<T>, T>; // triggers the instantiating the 'other' case and hence fails
        using U = typename std::conditional_t<std::is_unsigned_v<T>, std::make_signed<T>, std::type_identity<T>>::type; // NOLINT
        static_assert( std::is_same_v<T, T> );
        static_assert( std::is_same_v<E, U> );
    }
    {
        using E = float;
        using T = float;
        // using U = std::conditional_t<std::is_unsigned_v<T>, std::make_signed_t<T>, T>; // triggers the instantiating the 'other' case and hence fails
        using U = typename std::conditional_t<std::is_unsigned_v<T>, std::make_signed<T>, std::type_identity<T>>::type; // NOLINT
        static_assert( std::is_same_v<T, T> );
        static_assert( std::is_same_v<E, U> );
    }
    {
        // we shall ignore signedness like snprintf
        static_assert(true == jau::cfmt::check("         int -> int %d", 1));
        static_assert(true == jau::cfmt::check("unsigned int -> int %d", (unsigned int)1));
        static_assert(true == jau::cfmt::check("unsigned int -> unsigned int %u", (unsigned int)1));
        static_assert(true == jau::cfmt::check("         int -> unsigned int %u", 1));
        static_assert(true == jau::cfmt::check("        char -> int %d", (char)1)); // integral target type > given type
        static_assert(false == jau::cfmt::check(" error long -> int %d", (long)1)); // error: integral target type < given type

        static_assert(true == jau::cfmt::check(" %d", i));
        static_assert(true == jau::cfmt::check(" %f", fa));
        static_assert(true == jau::cfmt::check(" %zd", (ssize_t)1));
        static_assert(true == jau::cfmt::check(" %zu", (size_t)1));
        static_assert(true == jau::cfmt::check(" %" PRIi64 ".", (int64_t)1));
        static_assert(true == jau::cfmt::check(" %" PRIi64 ".", sz2));
        static_assert(true == jau::cfmt::check(" %p", pf));

        static_assert(0 == jau::cfmt::checkR("Hello World").argCount());
        static_assert(1 == jau::cfmt::checkR("Hello World %d", 1).argCount());
        static_assert(1 == jau::cfmt::checkR("Hello 1 %d", i).argCount());
        static_assert(true == jau::cfmt::check("Hello World"));
        static_assert(true == jau::cfmt::check("Hello World %d", 1));
        static_assert(true == jau::cfmt::check("Hello 1 %d", i));

        static_assert(1 == jau::cfmt::checkR("Hello 1 %.2f", fa).argCount());
        static_assert(1 == jau::cfmt::checkR("Hello 1 %.2f - end", fa).argCount());
        static_assert(2 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f - end", fa, fb).argCount());
        static_assert(3 == jau::cfmt::checkR("Hello 1 %.2f , 2 %2.2f, 3 %zu - end", fa, fb, sz1).argCount());
        static_assert(4 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 " - end", fa, fb, sz1, sz2).argCount());
        static_assert(5 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 ", 5 %03d - end", fa, fb, sz1, sz2, i).argCount());
        // static_assert(6 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 ", 5 %03d, 6 %p - end", fa, fb, sz1, sz2, i, pf).argCount());

        static_assert(false == jau::cfmt::check("Hello World %"));
        static_assert(0 > jau::cfmt::checkR("Hello World %").argCount());
        static_assert(0 > jau::cfmt::checkR("Hello 1 %d").argCount());
        static_assert(-1 == jau::cfmt::checkR("Hello 1 %d", fa).argCount());
        static_assert(-1 == jau::cfmt::checkR("Hello 1 %d", sz1).argCount());
        static_assert(-6 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 ", 5 %03d, 6 %p - end",
                                              fa, fb, sz1, sz2, i, i).argCount());
        static_assert(false == jau::cfmt::check("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 ", 5 %03d, 6 %p - end",
                                              fa, fb, sz1, sz2, i, i));

        const std::string s = jau_format_string_static("format_020a: %f, %f, %zu, %" PRIu64 ", %d\n",
                                                       fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, sz2 + 1_u64, i + 1);
        (void)s;
    }
    {
        constexpr bool b1 = std::is_nothrow_assignable_v<int&, uint64_t>;
        static_assert( b1, "Not Assignable" );
        constexpr bool b2 = std::is_nothrow_assignable_v<unsigned int&, long double>;
        static_assert( b2, "Not Assignable" );
        jau_format_string_static("Hello");
        jau_format_string_static("Hello %d", (int)2);
        jau_format_string_static("Hello %d", (unsigned int)2);
        jau_format_string_static("Hello %u", (unsigned int)2);
        jau_format_string_static("Hello %u", (int)2);

        // constexpr std::string_view fmt2 = "Hello %d"sv;
        // format_string_static2("Hello %d"sv, (int)2);
        // format_string_static2("Hello %d"s, (int)2);

        constexpr jau::cfmt::PResult c1 = jau::cfmt::checkR("Hello %u", (unsigned int)1);
        std::cerr << "XXX: " << __LINE__ << ": " << c1 << std::endl;
        REQUIRE(false == c1.error());
    }
    {
        constexpr jau::cfmt::PResult c1 = jau::cfmt::checkR("Hello World");
        REQUIRE(false == c1.error());
        REQUIRE(0 == c1.argCount());
        REQUIRE(0 == jau::cfmt::checkR("Hello World").argCount());
        constexpr jau::cfmt::PResult c3 = jau::cfmt::checkR("Hello 1 %d", i);
        REQUIRE(false == c3.error());
        REQUIRE(1 == c3.argCount());
        REQUIRE(9 == std::snprintf(buf, sizeof(buf), "Hello 1 %d", i));

        // `Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %li, 5 %03d, 6 %p - end`
        REQUIRE(1 == jau::cfmt::checkR("Hello 1 %.2f", fa).argCount());
        REQUIRE(1 == jau::cfmt::checkR("Hello 1 %.2f - end", fa).argCount());

        // 'Hello 1 %.2f, 2 %2.2f - end'
        jau::cfmt::PResult pc = jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f - end", fa, fb);
        std::cerr << "XXX: " << __LINE__ << ": " << pc << std::endl;
        REQUIRE(2 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f - end", fa, fb).argCount());

        // `Hello 1 %.2f, 2 %2.2f, 3 %zu - end`
        pc = jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu - end", fa, fb, sz1);
        std::cerr << "XXX: " << __LINE__ << ": " << pc << std::endl;
        REQUIRE(3 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu - end", fa, fb, sz1).argCount());

        REQUIRE(4 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 " - end", fa, fb, sz1, sz2).argCount());
        REQUIRE(5 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 ", 5 %03d - end", fa, fb, sz1, sz2, i).argCount());
        REQUIRE(6 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 ", 5 %03d, 6 %p - end", fa, fb, sz1, sz2, i, pf).argCount());

        // REQUIRE(13 == std::snprintf(buf, sizeof(buf), "Hello World %").argCount());
        REQUIRE(0 > jau::cfmt::checkR("Hello World %").argCount());
        REQUIRE(0 > jau::cfmt::checkR("Hello 1 %d").argCount());
        REQUIRE(-1 == jau::cfmt::checkR("Hello 1 %d", fa).argCount());
        REQUIRE(-1 == jau::cfmt::checkR("Hello 1 %d", sz1).argCount());
        REQUIRE(-6 == jau::cfmt::checkR("Hello 1 %.2f, 2 %2.2f, 3 %zu, 4 %" PRIi64 ", 5 %03d, 6 %p - end",
                                        fa, fb, sz1, sz2, i, i).argCount());
    }
}

TEST_CASE("jau::cfmt_01", "[jau][std::string][format_string]") {
    format_0a();
    format_0b();
}

/// Execute with `test_stringfmt --perf_analysis`
TEST_CASE("jau::cfmt_10", "[benchmark][jau][std::string][format_string]") {
    const size_t loops = 1000; // catch_auto_run ? 1000 : 1000;
    WARN("Benchmark with " + std::to_string(loops) + " loops");
    CHECK(true);

    BENCHMARK("fmt__check            bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            float fa = 1.1f, fb = 2.2f;
            size_t sz1 = 1;
            uint64_t sz2 = 2;
            int i1 = 3;

            size_t r = jau::cfmt::checkR("format_check: %.2f, %2.2f, %zu, %" PRIu64 ", %03d\n",
                                         fa, fb, sz1, sz2, i1).argCount();
            REQUIRE(5 == r);
            res = res + r;
        }
        return res;
    };
    BENCHMARK("fmt__check cnstexpr   bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            constexpr float fa = 1.1f, fb = 2.2f;
            constexpr size_t sz1 = 1;
            constexpr uint64_t sz2 = 2;
            constexpr int i1 = 3;

            constexpr  jau::cfmt::PResult pc = jau::cfmt::checkR("format_check: %.2f, %2.2f, %zu, %" PRIu64 ", %03d\n",
                                                                  fa, fb, sz1, sz2, i1);
            constexpr size_t r = pc.argCount();
            REQUIRE(5 == r);
            res = res + r;
        }
        return res;
    };
    BENCHMARK("fmt__check cnstexp2   bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            constexpr float fa = 1.1f, fb = 2.2f;
            constexpr size_t sz1 = 1;
            constexpr uint64_t sz2 = 2;
            constexpr int i1 = 3;

            constexpr  jau::cfmt2::PResult pc = jau::cfmt2::checkR("format_check: %.2f, %2.2f, %zu, %" PRIu64 ", %03d\n",
                                                                   fa, fb, sz1, sz2, i1);
            constexpr size_t r = pc.argCount();
            REQUIRE(5 == r);
            res = res + r;
        }
        return res;
    };
    BENCHMARK("format_000a_vsnprintf bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_000a_vsnprintf, false);
        }
        return res;
    };
    BENCHMARK("format_010a_vsnprintf bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_010a_vsnprintf, false);
        }
        return res;
    };
    BENCHMARK("fmt__020a macro       bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            {
                constexpr float fa = 1.1f, fb = 2.2f;
                constexpr size_t sz1 = 1;
                constexpr uint64_t a_u64 = 2;
                constexpr int j = 3;
                const std::string s = jau_format_string_static("format_020a: %f, %f, %zu, %" PRIu64 ", %d\n",
                                                               fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, j + 1);
                res = res + s.length();
            }
        }
        return res;
    };
    BENCHMARK("fmt__020a cnstexpr-in bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            {
                constexpr float fa = 1.1f, fb = 2.2f;
                constexpr size_t sz1 = 1;
                constexpr uint64_t a_u64 = 2;
                constexpr int j = 3;
                if constexpr( jau::cfmt::check("format_020a: %f, %f, %zu, %" PRIu64 ", %d\n",
                                               fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, j + 1) ) {
                    std::string s;
                    s.reserve(1023 + 1);  // incl. EOS
                    s.resize(1023);       // excl. EOS

                    // -Wformat=2 -> -Wformat -Wformat-nonliteral -Wformat-security -Wformat-y2k
                    // -Wformat=2 -Wformat-overflow=2 -Wformat-signedness
                    PRAGMA_DISABLE_WARNING_PUSH
                    PRAGMA_DISABLE_WARNING_FORMAT_NONLITERAL
                    const size_t nchars = std::snprintf(&s[0], 1023 + 1, "format_020a: %f, %f, %zu, %" PRIu64 ", %d\n",
                                                        fa + 1.0_f32, fb + 1.0_f32, sz1 + 1, a_u64 + 1_u64, j + 1);
                    PRAGMA_DISABLE_WARNING_POP
                    if( nchars < 1023 + 1 ) {
                        s.resize(nchars);
                        s.shrink_to_fit();
                    }  // else truncated w/ nchars > MaxStrLen
                    res = res + s.length();
                }
            }
        }
        return res;
    };
    BENCHMARK("fmt__020a_tsnprintf   bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_020a_tsnprintf, false);
        }
        return res;
    };
    BENCHMARK("format_030a_strstream bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_030a_strstream, false);
        }
        return res;
    };
#ifdef HAS_STD_FORMAT
    BENCHMARK("format_040a_stdformat bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < iterations; ++i ) {
            res = res + test_format(format_040a_stdformat, false);
        }
        return res;
    };
#endif

    BENCHMARK("format_000b_vsnprintf bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_000b_vsnprintf, false);
        }
        return res;
    };
    BENCHMARK("format_010b_vsnprintf bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_010b_vsnprintf, false);
        }
        return res;
    };
    BENCHMARK("format_020b__snprintf bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_020b_tsnprintf, false);
        }
        return res;
    };
    BENCHMARK("format_030b_strstream bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < loops; ++i ) {
            res = res + test_format(format_030b_strstream, false);
        }
        return res;
    };
#ifdef HAS_STD_FORMAT
    BENCHMARK("format_040b_stdformat bench") {
        volatile size_t res = 0;
        for( size_t i = 0; i < iterations; ++i ) {
            res = res + test_format(format_040b_stdformat, false);
        }
        return res;
    };
#endif
}