-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathicecream.hpp
5223 lines (4427 loc) · 163 KB
/
icecream.hpp
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2019-2020 The IceCream-Cpp Developers. See the AUTHORS file at the
* top-level directory of this distribution and at
* https://github.com/renatoGarcia/icecream-cpp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ICECREAM_HPP_INCLUDED
#define ICECREAM_HPP_INCLUDED
#include <cassert>
#include <cerrno>
#include <clocale>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cwchar>
#include <exception>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <memory>
#include <mutex>
#include <ostream>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#if !defined(__APPLE__) && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 15000)
#define ICECREAM_CUCHAR_HEADER
#include <cuchar>
#endif
#if defined(__cpp_lib_optional) || (__cplusplus >= 201703L)
#define ICECREAM_OPTIONAL_HEADER
#include <optional>
#endif
#if defined(__cpp_lib_variant) || (__cplusplus >= 201703L)
#define ICECREAM_VARIANT_HEADER
#include <variant>
#endif
#if defined(__cpp_lib_string_view) || (__cplusplus >= 201703L)
#define ICECREAM_STRING_VIEW_HEADER
#include <string_view>
#endif
#if defined(__has_builtin) && defined(__clang__)
#if __has_builtin(__builtin_dump_struct) && __clang_major__ >= 15
#define ICECREAM_DUMP_STRUCT_CLANG
#endif
#endif
#if defined(__has_include) && __has_include(<ranges>)
#include <ranges>
#if defined(__cpp_lib_ranges)
#define ICECREAM_LIB_RANGES
#endif
#endif
#if !defined(__APPLE__) && defined(__has_include) && __has_include(<source_location>)
#include <source_location>
#if defined(__cpp_lib_source_location)
#define ICECREAM_SOURCE_LOCATION
#endif
#endif
#if defined(__has_include) && __has_include(<format>)
#include <format>
#if defined(__cpp_lib_format) || (_LIBCPP_VERSION >= 170000 && __cplusplus >= 202002L)
// libc++ just defines the '__cpp_lib_format' macro start from version 19. However
// from version 17 it already implemens all functionalities that we need.
#define ICECREAM_STL_FORMAT
#endif
#if defined(__cpp_lib_format_ranges)
#define ICECREAM_STL_FORMAT_RANGES
#endif
#endif
// ICECREAM_FMT is the macro which can be defined to enable {fmt} support regardless of
// any other condition.
//
// The "defined()" test for FMT_VERSION macro is an attempt to check if any {fmt} header
// was "#included" before the including of this Icecream-cpp header. If so, the {fmt}
// support will be enabled.
#if defined(ICECREAM_FMT) || defined(FMT_VERSION)
// All the {fmt} headers from supoorted versions (5.0 and newer) will directly or
// indirectly include a source file where FMT_VERSION is defined.
#include <fmt/format.h>
#define ICECREAM_FMT_ENABLED
#endif
// ICECREAM_RANGE_V3 is the macro which can be defined to enable range-v3 support
// regardless of any other condition.
//
// The "defined()" test for RANGES_V3_DETAIL_CONFIG_HPP macro is an attempt to check if
// any range-v3 header was "#included" before the including of this icecream-cpp header.
// If so, the range-v3 support will be enabled.
#if defined(ICECREAM_RANGE_V3) || defined(RANGES_V3_DETAIL_CONFIG_HPP)
// The RANGES_V3_DETAIL_CONFIG_HPP is the include guard of the header
// <range/v3/detail/config.hpp>. This header is present in all range-v3 releases, and
// is direct or indirectly included by all other range-v3 headers, excepting a few
// ones like <range/v3/version.hpp>. Because of that, checking by the definition of
// RANGES_V3_DETAIL_CONFIG_HPP is a good way to determine if any range-v3 header was
// previously included.
#define ICECREAM_RANGE_V3_ENABLED
#include <range/v3/version.hpp>
#include <range/v3/view/transform.hpp>
namespace icecream { namespace detail {
#if RANGE_V3_VERSION <= 500
namespace rv3v = ::ranges::view;
#else
namespace rv3v = ::ranges::views;
#endif
}}
#endif
#define ICECREAM_DEV_HASH "$Format:%H$"
#if defined(__GNUC__)
#define ICECREAM_FUNCTION __PRETTY_FUNCTION__
#elif defined(_MSC_VER)
#define ICECREAM_FUNCTION __FUNCSIG__
#else
#define ICECREAM_FUNCTION __func__
#endif
// Used to force MSVC to unpack __VA_ARGS__
#define ICECREAM_EXPAND(X) X
// Returns the number of args of a callable on IC_A macro. To be able to measure
// 0 arguments, the first name of the input __VA_ARGS__ must be the callable
// itself. In other words, this macro will return one less than the size of its
// inputs.
#define ICECREAM_ARGS_SIZE(...) ICECREAM_EXPAND(ICECREAM_ARGS_SIZE_( \
__VA_ARGS__, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, \
21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, \
6, 5, 4, 3, 2, 1, 0))
#define ICECREAM_ARGS_SIZE_( \
_0, _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, N, ...) N
#define ICECREAM_UNPACK_0
#define ICECREAM_UNPACK_1 std::get<0>(std::move(ret_tuple))
#define ICECREAM_UNPACK_2 ICECREAM_UNPACK_1, std::get<1>(std::move(ret_tuple))
#define ICECREAM_UNPACK_3 ICECREAM_UNPACK_2, std::get<2>(std::move(ret_tuple))
#define ICECREAM_UNPACK_4 ICECREAM_UNPACK_3, std::get<3>(std::move(ret_tuple))
#define ICECREAM_UNPACK_5 ICECREAM_UNPACK_4, std::get<4>(std::move(ret_tuple))
#define ICECREAM_UNPACK_6 ICECREAM_UNPACK_5, std::get<5>(std::move(ret_tuple))
#define ICECREAM_UNPACK_7 ICECREAM_UNPACK_6, std::get<6>(std::move(ret_tuple))
#define ICECREAM_UNPACK_8 ICECREAM_UNPACK_7, std::get<7>(std::move(ret_tuple))
#define ICECREAM_UNPACK_9 ICECREAM_UNPACK_8, std::get<8>(std::move(ret_tuple))
#define ICECREAM_UNPACK_10 ICECREAM_UNPACK_9, std::get<9>(std::move(ret_tuple))
#define ICECREAM_UNPACK_11 ICECREAM_UNPACK_10, std::get<10>(std::move(ret_tuple))
#define ICECREAM_UNPACK_12 ICECREAM_UNPACK_11, std::get<11>(std::move(ret_tuple))
#define ICECREAM_UNPACK_13 ICECREAM_UNPACK_12, std::get<12>(std::move(ret_tuple))
#define ICECREAM_UNPACK_14 ICECREAM_UNPACK_13, std::get<13>(std::move(ret_tuple))
#define ICECREAM_UNPACK_15 ICECREAM_UNPACK_14, std::get<14>(std::move(ret_tuple))
#define ICECREAM_UNPACK_16 ICECREAM_UNPACK_15, std::get<15>(std::move(ret_tuple))
#define ICECREAM_UNPACK_17 ICECREAM_UNPACK_16, std::get<16>(std::move(ret_tuple))
#define ICECREAM_UNPACK_18 ICECREAM_UNPACK_17, std::get<17>(std::move(ret_tuple))
#define ICECREAM_UNPACK_19 ICECREAM_UNPACK_18, std::get<18>(std::move(ret_tuple))
#define ICECREAM_UNPACK_20 ICECREAM_UNPACK_19, std::get<19>(std::move(ret_tuple))
#define ICECREAM_UNPACK_21 ICECREAM_UNPACK_20, std::get<20>(std::move(ret_tuple))
#define ICECREAM_UNPACK_22 ICECREAM_UNPACK_21, std::get<21>(std::move(ret_tuple))
#define ICECREAM_UNPACK_23 ICECREAM_UNPACK_22, std::get<22>(std::move(ret_tuple))
#define ICECREAM_UNPACK_24 ICECREAM_UNPACK_23, std::get<23>(std::move(ret_tuple))
#define ICECREAM_UNPACK_25 ICECREAM_UNPACK_24, std::get<24>(std::move(ret_tuple))
#define ICECREAM_UNPACK_26 ICECREAM_UNPACK_25, std::get<25>(std::move(ret_tuple))
#define ICECREAM_UNPACK_27 ICECREAM_UNPACK_26, std::get<26>(std::move(ret_tuple))
#define ICECREAM_UNPACK_28 ICECREAM_UNPACK_27, std::get<27>(std::move(ret_tuple))
#define ICECREAM_UNPACK_29 ICECREAM_UNPACK_28, std::get<28>(std::move(ret_tuple))
#define ICECREAM_UNPACK_30 ICECREAM_UNPACK_29, std::get<29>(std::move(ret_tuple))
#define ICECREAM_UNPACK_31 ICECREAM_UNPACK_30, std::get<30>(std::move(ret_tuple))
#define ICECREAM_UNPACK_32 ICECREAM_UNPACK_31, std::get<31>(std::move(ret_tuple))
#define ICECREAM_APPLY_(fmt, argument_names, N, callable, ...) \
[&]() \
{ \
auto ret_tuple = ::icecream::detail::ensure_tuple( \
ICECREAM_EXPAND(ICECREAM_DISPATCH(true, fmt, argument_names, __VA_ARGS__)) \
); \
(void) ret_tuple; \
return callable(ICECREAM_UNPACK_##N); \
}()
#define ICECREAM_APPLY(fmt, argument_names, N, ...) \
ICECREAM_EXPAND(ICECREAM_APPLY_(fmt, argument_names, N, __VA_ARGS__))
#define ICECREAM_DISPATCH(is_ic_apply, fmt, argument_names, ...) \
::icecream::detail::Dispatcher{ \
is_ic_apply, IC_CONFIG, __FILE__, __LINE__, ICECREAM_FUNCTION, fmt, argument_names \
}.ret(__VA_ARGS__)
#if defined(ICECREAM_LONG_NAME)
#define ICECREAM(...) ICECREAM_DISPATCH(false, "", #__VA_ARGS__, __VA_ARGS__)
#define ICECREAM0() ICECREAM_DISPATCH(false, "", "")
#define ICECREAM_F(fmt, ...) ICECREAM_DISPATCH(false, fmt, #__VA_ARGS__, __VA_ARGS__)
#define ICECREAM_A(...) ICECREAM_APPLY("", #__VA_ARGS__, ICECREAM_ARGS_SIZE(__VA_ARGS__), __VA_ARGS__)
#define ICECREAM_FA(fmt, ...) ICECREAM_APPLY(fmt, #__VA_ARGS__, ICECREAM_ARGS_SIZE(__VA_ARGS__), __VA_ARGS__)
#define ICECREAM_(...) ::icecream::detail::make_formatting_argument(__VA_ARGS__)
#define ICECREAM_V(...) ::icecream::detail::IC_V_(__VA_ARGS__).complete(ICECREAM_CONFIG, __LINE__, __FILE__, ICECREAM_FUNCTION)
#define ICECREAM_FV(...) ::icecream::detail::IC_FV_(__VA_ARGS__).complete(ICECREAM_CONFIG, __LINE__, __FILE__, ICECREAM_FUNCTION)
#define ICECREAM_CONFIG_SCOPE() \
auto const* const icecream_parent_config_5f803a3bcdb4 = &icecream_config_5f803a3bcdb4; \
::icecream::Config icecream_config_5f803a3bcdb4(icecream_parent_config_5f803a3bcdb4);
#define ICECREAM_CONFIG icecream_config_5f803a3bcdb4
#else
#define IC(...) ICECREAM_DISPATCH(false, "", #__VA_ARGS__, __VA_ARGS__)
#define IC0() ICECREAM_DISPATCH(false, "", "")
#define IC_F(fmt, ...) ICECREAM_DISPATCH(false, fmt, #__VA_ARGS__, __VA_ARGS__)
#define IC_A(...) ICECREAM_APPLY("", #__VA_ARGS__, ICECREAM_ARGS_SIZE(__VA_ARGS__), __VA_ARGS__)
#define IC_FA(fmt, ...) ICECREAM_APPLY(fmt, #__VA_ARGS__, ICECREAM_ARGS_SIZE(__VA_ARGS__), __VA_ARGS__)
#define IC_(...) ::icecream::detail::make_formatting_argument(__VA_ARGS__)
#define IC_V(...) ::icecream::detail::IC_V_(__VA_ARGS__).complete(IC_CONFIG, __LINE__, __FILE__, ICECREAM_FUNCTION)
#define IC_FV(...) ::icecream::detail::IC_FV_(__VA_ARGS__).complete(IC_CONFIG, __LINE__, __FILE__, ICECREAM_FUNCTION)
#define IC_CONFIG_SCOPE() \
auto const* const icecream_parent_config_5f803a3bcdb4 = &icecream_config_5f803a3bcdb4; \
::icecream::Config icecream_config_5f803a3bcdb4(icecream_parent_config_5f803a3bcdb4);
#define IC_CONFIG icecream_config_5f803a3bcdb4
#endif
#define ICECREAM_ASSERT(exp, msg) assert(((void)msg, exp))
#define ICECREAM_UNREACHABLE assert(((void)"Should not reach here. Please report the bug", false))
namespace boost
{
class exception;
// Forward declare this internal function because boost::diagnostic_information has a
// default argument, and if this icecream.hpp header is included before the boost
// exception headers it will trigger a compile error: redeclaration of ‘template<class
// T> std::string boost::diagnostic_information(const T&, bool)’ may not have default
// arguments
namespace exception_detail
{
std::string diagnostic_information_impl(
boost::exception const*, std::exception const*, bool, bool
);
}
template <typename T> class scoped_ptr;
template <typename T> class weak_ptr;
namespace variant2
{
template<typename... T> class variant;
template <typename R, typename Visitor, typename Variant>
constexpr auto visit(Visitor&& vis, Variant&& var) -> R;
}
}
namespace icecream{ namespace detail
{
// To allow ADL to find custom `begin`, `end`, `size`, and `to_string` function overloads
using std::begin;
using std::end;
#if defined(__cpp_lib_nonmember_container_access)
using std::size;
#endif
using std::to_string;
// -------------------------------------------------- is_instantiation
// Checks if a type T (like std::pair<int, float>) is an instantiation of a template
// class U (like std::pair<typename T0, typename T1>).
template <template<typename...> class, typename...>
struct is_instantiation: std::false_type {};
template <template<typename...> class U, typename... T>
struct is_instantiation<U, U<T...>>: std::true_type {};
// -------------------------------------------------- conjunction
// Logical AND
template <typename... Ts>
struct conjunction: std::true_type {};
template <typename T, typename... Ts>
struct conjunction<T, Ts...>:
std::conditional<
T::value,
conjunction<Ts...>,
std::false_type
>::type
{};
// -------------------------------------------------- disjunction
// Logical OR
template <typename... Ts>
struct disjunction: std::false_type {};
template <typename T, typename... Ts>
struct disjunction<T, Ts...>:
std::conditional<
T::value,
std::true_type,
disjunction<Ts...>
>::type
{};
// -------------------------------------------------- negation
// Logical NOT
template <typename T>
using negation =
typename std::conditional<
T::value,
std::false_type,
std::true_type
>::type;
// -------------------------------------------------- remove_cvref
template <typename T>
using remove_cvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
// -------------------------------------------------- int_sequence
template <int...>
struct int_sequence {};
template <int N, int... S>
struct int_sequence_generator: int_sequence_generator<N-1, N-1, S...> {};
template <int... S>
struct int_sequence_generator<0, S...>
{
typedef int_sequence<S...> type;
};
template <int N>
using make_int_sequence = typename int_sequence_generator<N>::type;
// -------------------------------------------------- is_bounded_array
// Checks if T is an array with a known size.
template <typename T>
struct is_bounded_array_impl: std::false_type {};
template <typename T, size_t N>
struct is_bounded_array_impl<T[N]>: std::true_type {};
template <typename T>
using is_bounded_array =
typename is_bounded_array_impl<typename std::remove_reference<T>::type>::type;
// -------------------------------------------------- is_invocable
// Checks if T is nullary invocable, i.e.: the statement T() is valid.
template <typename T>
auto is_invocable_impl(int) -> decltype(std::declval<T&>()(), std::true_type{});
template <typename T>
auto is_invocable_impl(...) -> std::false_type;
template <typename T>
using is_invocable = decltype(is_invocable_impl<T>(0));
// -------------------------------------------------- is_string_convertible
// Checks if T is nullary invocable, i.e.: the statement T(U) is valid.
template <typename T>
auto is_string_convertible_impl(int) -> decltype(std::string(std::declval<T&>()), std::true_type{});
template <typename T>
auto is_string_convertible_impl(...) -> std::false_type;
template <typename T>
using is_string_convertible = decltype(is_string_convertible_impl<T>(0));
// -------------------------------------------------- returned_type
// Returns the result type of nullary function
template <typename T>
auto returned_type_impl(int) -> decltype(std::declval<T&>()());
template <typename T>
auto returned_type_impl(...) -> void;
template <typename T>
using returned_type = decltype(returned_type_impl<T>(0));
// -------------------------------------------------- resolve_view_t
template <typename T>
auto resolve_view_t_impl(int) -> decltype(std::declval<std::vector<int>&>() | std::declval<T&>());
template <typename T>
auto resolve_view_t_impl(...) -> void;
template <typename T>
using resolve_view_t = decltype(resolve_view_t_impl<T>(0));
// -------------------------------------------------- is_sized
// Checks if a class `T` has either a `size()` method or a `size(T const&)` overload.
template <typename T>
auto has_size_method_impl(int) ->
decltype(
std::declval<T&>().size(),
std::true_type{}
);
template <typename T>
auto has_size_method_impl(...) -> std::false_type;
template <typename T>
auto has_size_overload_impl(int) ->
decltype(
size(std::declval<T&>()),
std::true_type{}
);
template <typename T>
auto has_size_overload_impl(...) -> std::false_type;
template <typename T>
using is_sized =
typename disjunction<
decltype(has_size_method_impl<T>(0)),
decltype(has_size_overload_impl<T>(0))
>::type;
template <typename T>
using has_size_method = decltype(has_size_method_impl<T>(0));
template <typename T>
using has_size_function_overload = decltype(has_size_overload_impl<T>(0));
// -------------------------------------------------- is_sentinel_for
template <typename S, typename I>
auto is_sentinel_for_impl(int) ->
decltype (
S(std::declval<S&>()),
std::declval<S&>() = std::declval<S&>(),
std::declval<I&>() != std::declval<S&>(),
std::declval<I&>() == std::declval<S&>(),
std::true_type{}
);
template <typename S, typename I>
auto is_sentinel_for_impl(...) -> std::false_type;
template <typename S, typename I>
using is_sentinel_for = decltype(is_sentinel_for_impl<S, I>(0));
// -------------------------------------------------- is_range
template <typename R>
auto is_range_impl(int) ->
decltype (
begin(std::declval<R&>()),
end(std::declval<R&>()),
std::true_type{}
);
template <typename R>
auto is_range_impl(...) -> std::false_type;
template <typename R>
using is_range = decltype(is_range_impl<R>(0));
// -------------------------------------------------- get_iterator_t
template <typename R>
using get_iterator_t = decltype(begin(std::declval<R&>()));
// -------------------------------------------------- get_reference_t
template <typename I>
using get_reference_t = decltype(*std::declval<I&>());
// -------------------------------------------------- is_input_iterator
template <typename T>
auto is_input_iterator_impl(int) ->
decltype (
*std::declval<T&>(), // is dereferenciable
++std::declval<T&>(), // is pre-incrementable
std::true_type{}
);
template <typename T>
auto is_input_iterator_impl(...) -> std::false_type;
template <typename T>
using is_input_iterator = decltype(is_input_iterator_impl<T>(0));
// -------------------------------------------------- is_input_range
template <typename T>
using is_input_range =
typename conjunction<
is_range<T>,
is_input_iterator<get_iterator_t<T>>
>::type;
// -------------------------------------------------- is_forward_iterator
template <typename I>
auto is_forward_iterator_impl(int) ->
decltype (
I(std::declval<I&>()), // is copyable
I(), // is default initializable
std::declval<I&>() == std::declval<I&>(), // is copyable
std::declval<I&>() != std::declval<I&>(), // is copyable
std::true_type{}
);
template <typename I>
auto is_forward_iterator_impl(...) -> std::false_type;
template <typename I>
using is_forward_iterator =
typename conjunction<
is_input_iterator<I>,
is_sentinel_for<I, I>,
decltype(is_forward_iterator_impl<I>(0))
>::type;
// -------------------------------------------------- is_forward_range
template <typename R>
using is_forward_range =
typename conjunction<
is_input_range<R>,
is_forward_iterator<get_iterator_t<R>>
>::type;
// -------------------------------------------------- is_bidirectional_iterator
template <typename I>
auto is_bidirectional_iterator_impl(int) ->
decltype (
--std::declval<I&>(),
std::declval<I&>()--,
std::true_type{}
);
template <typename I>
auto is_bidirectional_iterator_impl(...) -> std::false_type;
template <typename I>
using is_bidirectional_iterator =
typename conjunction<
is_forward_iterator<I>,
decltype(is_bidirectional_iterator_impl<I>(0))
>::type;
// -------------------------------------------------- is_bidirectional_range
template <typename R>
using is_bidirectional_range =
typename conjunction<
is_forward_range<R>,
is_bidirectional_iterator<get_iterator_t<R>>
>::type;
// -------------------------------------------------- has_push_back_T
// Checks if the class `C` has a method push_back(`T`)
template <typename C, typename T>
auto has_push_back_T_impl(int) ->
decltype(
std::declval<C&>().push_back(std::declval<T&>()),
std::true_type{}
);
template <typename C, typename T>
auto has_push_back_T_impl(...) -> std::false_type;
template <typename C, typename T>
using has_push_back_T = decltype(has_push_back_T_impl<C, T>(0));
// --------------------------------------------------is_streamable
// Checks if T has an insertion overload, i.e.: std::ostream& << T&
template <typename T>
auto is_streamable_impl(int) ->
decltype(
std::declval<std::ostream&>() << std::declval<T&>(),
std::true_type{}
);
template <typename T>
auto is_streamable_impl(...) -> std::false_type;
template <typename T>
using is_streamable = decltype(is_streamable_impl<T>(0));
// --------------------------------------------------is_stl_formattable
#if defined(ICECREAM_STL_FORMAT)
template <class T>
auto is_stl_formattable_impl(int) ->
decltype(
std::formatter<T, char>{},
std::true_type{}
);
#endif
template <class T>
auto is_stl_formattable_impl(...) -> std::false_type ;
template <class T>
using is_stl_formattable = decltype(is_stl_formattable_impl<remove_cvref_t<T>>(0));
// --------------------------------------------------is_fmt_formattable
#if defined(ICECREAM_FMT_ENABLED)
template <class T>
auto is_fmt_formattable_impl(int) ->
decltype(
fmt::formatter<T, char>{},
std::true_type{}
);
#endif
template <class T>
auto is_fmt_formattable_impl(...) -> std::false_type ;
template <class T>
using is_fmt_formattable = decltype(is_fmt_formattable_impl<remove_cvref_t<T>>(0));
// --------------------------------------------------is_baseline_printable
template <typename T>
using is_baseline_printable =
typename disjunction<
is_streamable<T>, is_stl_formattable<T>, is_fmt_formattable<T>
>::type;
// -------------------------------------------------- has_to_string
template <typename T>
auto has_to_string_impl(int) ->
decltype(
to_string(std::declval<T&>()),
std::true_type{}
);
template <typename T>
auto has_to_string_impl(...) -> std::false_type;
template <typename T>
using has_to_string = decltype(has_to_string_impl<T>(0));
// -------------------------------------------------- is_tuple
// Checks if T is a tuple like type, i.e.: an instantiation of one of
// std::pair<typename U0, typename U1> or std::tuple<typename... Us>.
template <typename T>
using is_tuple =
typename disjunction<
is_instantiation<std::pair, remove_cvref_t<T>>,
is_instantiation<std::tuple, remove_cvref_t<T>>
>::type;
// -------------------------------------------------- is_character
// Checks if T is character type (char, char16_t, etc).
template <typename T>
using is_character =
typename disjunction<
std::is_same<typename std::decay<T>::type, char>,
std::is_same<typename std::decay<T>::type, wchar_t>,
#if defined(__cpp_char8_t)
std::is_same<typename std::decay<T>::type, char8_t>,
#endif
std::is_same<typename std::decay<T>::type, char16_t>,
std::is_same<typename std::decay<T>::type, char32_t>
>::type;
// -------------------------------------------------- is_xsig_char
template <typename T>
using is_xsig_char =
typename disjunction<
std::is_same<typename std::decay<T>::type, signed char>,
std::is_same<typename std::decay<T>::type, unsigned char>
>::type;
// -------------------------------------------------- is_c_string
// Checks if T is C string type, i.e.: either char* or char[]. A char[N] is not
// considered a C string.
template <typename T>
using is_c_string =
typename conjunction<
negation<is_bounded_array<T>>,
disjunction<
std::is_same<typename std::decay<T>::type, char*>,
std::is_same<typename std::decay<T>::type, char const*>,
std::is_same<typename std::decay<T>::type, signed char*>,
std::is_same<typename std::decay<T>::type, signed char const*>,
std::is_same<typename std::decay<T>::type, unsigned char*>,
std::is_same<typename std::decay<T>::type, unsigned char const*>,
std::is_same<typename std::decay<T>::type, wchar_t*>,
std::is_same<typename std::decay<T>::type, wchar_t const*>,
#if defined(__cpp_char8_t)
std::is_same<typename std::decay<T>::type, char8_t*>,
std::is_same<typename std::decay<T>::type, char8_t const*>,
#endif
std::is_same<typename std::decay<T>::type, char16_t*>,
std::is_same<typename std::decay<T>::type, char16_t const*>,
std::is_same<typename std::decay<T>::type, char32_t*>,
std::is_same<typename std::decay<T>::type, char32_t const*>
>
>::type;
// -------------------------------------------------- is_std_string
// Checks if T is a std::basic_string<typename U>
template <typename T>
using is_std_string = typename is_instantiation<std::basic_string, remove_cvref_t<T>>::type;
// -------------------------------------------------- is_string_view
// Checks if T is a std::basic_string_view<typename U>
template <typename T>
using is_string_view =
typename disjunction<
#if defined(ICECREAM_STRING_VIEW_HEADER)
is_instantiation<std::basic_string_view, remove_cvref_t<T>>
#endif
>::type;
// -------------------------------------------------- is_collection
// Checks if T is a collection, i.e.: a range type that is not a std::string.
template <typename T>
using is_collection =
typename conjunction<
is_range<T>, negation<is_std_string<T>>, negation<is_string_view<T>>
>::type;
// -------------------------------------------------- is_variant
// Checks if T is a variant type.
template <typename T>
using is_variant =
typename disjunction<
is_instantiation<boost::variant2::variant, remove_cvref_t<T>>
#if defined(ICECREAM_VARIANT_HEADER)
, is_instantiation<std::variant, remove_cvref_t<T>>
#endif
>::type;
// -------------------------------------------------- is_optional
// Checks if T is an optional type.
template <typename T>
using is_optional =
typename disjunction<
#if defined(ICECREAM_OPTIONAL_HEADER)
is_instantiation<std::optional, remove_cvref_t<T>>
#endif
>::type;
// -------------------------------------------------- is_not_streamable_ptr
// Checks if T is either std::unique_ptr<typename U> instantiation (Until C++20), or a
// boost::scoped_ptr<typename U>. Both are without an operator<<(ostream&) overload.
template <typename T>
using is_unstreamable_ptr =
typename disjunction<
is_instantiation<std::unique_ptr, remove_cvref_t<T>>,
is_instantiation<boost::scoped_ptr, remove_cvref_t<T>>
>::type;
// -------------------------------------------------- is_weak_ptr
// Checks if T is a instantiation if either std::weak_ptr<typename U> or
// boost::weak_ptr<typename U>.
template <typename T>
using is_weak_ptr =
typename disjunction<
is_instantiation<std::weak_ptr, remove_cvref_t<T>>,
is_instantiation<boost::weak_ptr, remove_cvref_t<T>>
>::type;
// -------------------------------------------------- is_valid_prefix
// Checks if T can be used as prefix, i.e.: T is a string or a nullary function
// returning a type that has a "ostream <<" overload.
template <typename T>
using is_valid_prefix =
typename disjunction<
is_std_string<T>,
is_string_view<T>,
is_c_string<typename std::decay<T>::type>,
conjunction<
is_invocable<T>,
is_streamable<returned_type<T>>
>
>::type;
// -------------------------------------------------- is_T_output_iterator
// Checks if `Iterator` is an output iterator with type `Item`
template <typename Iterator, typename Item>
auto is_T_output_iterator_impl(int) ->
decltype(
*std::declval<Iterator&>() = std::declval<Item&>(),
std::true_type{}
);
template <typename Iterator, typename Item>
auto is_T_output_iterator_impl(...) -> std::false_type;
template <typename Iterator, typename Item>
using is_T_output_iterator = decltype(is_T_output_iterator_impl<Iterator, Item>(0));
// -------------------------------------------------- is_handled_by_clang_dump_struct
template <typename T>
using is_handled_by_clang_dump_struct =
typename negation<
disjunction<
is_collection<T>,
is_tuple<T>,
is_unstreamable_ptr<T>,
is_weak_ptr<T>,
is_std_string<T>,
is_string_view<T>,
is_variant<T>,
is_optional<T>,
is_baseline_printable<T>,
is_character<T>,
is_c_string<T>,
std::is_base_of<std::exception, remove_cvref_t<T>>,
std::is_base_of<boost::exception, remove_cvref_t<T>>
>
>::type;
// -------------------------------------------- Forward declare all make_printing_branch overloads
// This is required because the declarations must be visible by some implementation
// that can need to delegate the printing to other overload. For example when a
// printing a std::vector<std::tuple<int, float>>>, fist the range implementation will
// be called, then it will delegate the printing to the tuple overload, then finally
// it will delegate the printing to the operator<<(std::ostream&, T) overload.
} // namespace detail
class Config;
namespace detail {
class PrintingNode;
class StringView;
// Print any class that overloads operator<<(std::ostream&, T)
template <typename T>
auto make_printing_branch(
T&&, StringView, Config const&
) ->
typename std::enable_if<
is_streamable<T>::value
&& !is_stl_formattable<T>::value
&& !is_fmt_formattable<T>::value
&& !is_c_string<T>::value
&& !is_character<T>::value
&& !is_xsig_char<T>::value
&& !is_std_string<T>::value
&& !is_string_view<T>::value
&& !std::is_array<remove_cvref_t<T>>::value,
PrintingNode
>::type;
#if defined(ICECREAM_STL_FORMAT)
// Print any class that specializes std::formatter<T, char>
template <typename T>
auto make_printing_branch(
T&&, StringView, Config const&
) ->
typename std::enable_if<
is_stl_formattable<T>::value
&& !is_fmt_formattable<T>::value
&& !is_c_string<T>::value
&& !is_character<T>::value
&& !is_xsig_char<T>::value
&& !is_std_string<T>::value
&& !is_string_view<T>::value
&& !std::is_array<remove_cvref_t<T>>::value,
PrintingNode
>::type;
#endif
#if defined(ICECREAM_FMT_ENABLED)
// Print any class that specializes fmt::formatter<T, char>
template <typename T>
auto make_printing_branch(
T&&, StringView, Config const&
) ->
typename std::enable_if<
is_fmt_formattable<T>::value
&& !is_c_string<T>::value
&& !is_character<T>::value
&& !is_xsig_char<T>::value
&& !is_std_string<T>::value
&& !is_string_view<T>::value
&& !std::is_array<remove_cvref_t<T>>::value,
PrintingNode
>::type;
#endif
// Print C string
template <typename T>
auto make_printing_branch(
T&&, StringView, Config const&
) -> typename std::enable_if<is_c_string<T>::value, PrintingNode>::type;
// Print std::string
template <typename T>
auto make_printing_branch(
T&&, StringView, Config const&
) -> typename std::enable_if<is_std_string<T>::value, PrintingNode>::type;
#if defined(ICECREAM_STRING_VIEW_HEADER)
// Print std::string_view
template <typename T>
auto make_printing_branch(
T&&, StringView, Config const&
) -> typename std::enable_if<is_string_view<T>::value, PrintingNode>::type;
#endif