84
84
// `#define DEBUG_SHOW_TIMESTAMP 2` (default) - printing timestamp relative to
85
85
// program staring time rather than system real time
86
86
//
87
+ // `#define DEBUG_SHOW_THREAD_ID 0` (default) - do not print the thread id
88
+ // `#define DEBUG_SHOW_THREAD_ID 1` - print the current thread id
89
+ //
87
90
// `#define DEBUG_SHOW_LOCATION 1` (default) - show source location mark before
88
91
// each line of the debug output (e.g. "file.cpp:233")
89
92
// `#define DEBUG_SHOW_LOCATION 0` - do not show the location mark
298
301
# include < unordered_map>
299
302
# endif
300
303
# ifndef DEBUG_SOURCE_LOCATION
301
- # if __cplusplus >= 202'002L
304
+ # if __cplusplus >= 202002L
302
305
# if defined(__has_include)
303
306
# if __has_include(<source_location>)
304
307
# include < source_location>
310
313
# endif
311
314
# endif
312
315
# ifndef DEBUG_SOURCE_LOCATION
313
- # if __cplusplus >= 201'505L
316
+ # if __cplusplus >= 201505L
314
317
# if defined(__has_include)
315
318
# if __has_include(<experimental/source_location>)
316
319
# include < experimental/source_location>
352
355
# elif DEBUG_SHOW_TIMESTAMP == 2
353
356
# include < chrono>
354
357
# endif
358
+ # if DEBUG_SHOW_THREAD_ID
359
+ # include < thread>
360
+ # endif
355
361
# if defined(__has_include)
356
362
# if __has_include(<variant>)
357
363
# include < variant>
358
364
# endif
359
365
# endif
360
366
# ifndef DEBUG_STRING_VIEW
361
367
# if defined(__has_include)
362
- # if __cplusplus >= 201'703L
368
+ # if __cplusplus >= 201703L
363
369
# if __has_include(<string_view>)
364
370
# include < string_view>
365
371
# if __cpp_lib_string_view
373
379
# include < string>
374
380
# define DEBUG_STRING_VIEW std::string
375
381
# endif
376
- # if __cplusplus >= 202'002L
382
+ # if __cplusplus >= 202002L
377
383
# if defined(__has_cpp_attribute)
378
384
# if __has_cpp_attribute(unlikely)
379
385
# define DEBUG_UNLIKELY [[unlikely]]
@@ -462,7 +468,7 @@ struct DEBUG_NODISCARD debug {
462
468
}
463
469
464
470
struct debug_special_void {
465
- char const (&repr ())[5] const {
471
+ char const (&repr () const )[5] {
466
472
return " void" ;
467
473
}
468
474
};
@@ -722,15 +728,15 @@ struct DEBUG_NODISCARD debug {
722
728
bool add_comma = false ;
723
729
std::apply (
724
730
[&](auto &&...args ) {
725
- (([&] {
726
- if (add_comma) {
727
- oss << DEBUG_TUPLE_COMMA;
728
- }
729
- add_comma = true ;
730
- debug_format (oss, std::forward<decltype (args)>(args));
731
- }()),
732
- ...);
733
- },
731
+ (([&] {
732
+ if (add_comma) {
733
+ oss << DEBUG_TUPLE_COMMA;
734
+ }
735
+ add_comma = true ;
736
+ debug_format (oss, std::forward<decltype (args)>(args));
737
+ }()),
738
+ ...);
739
+ },
734
740
t);
735
741
oss << DEBUG_TUPLE_BRACE[1 ];
736
742
} else if constexpr (std::is_enum<T>::value) {
@@ -829,6 +835,12 @@ struct DEBUG_NODISCARD debug {
829
835
std::declval<T const &>().get ()));
830
836
DEBUG_COND (is_optional, (((void )*std::declval<T const &>(), (void )0 ),
831
837
((void )(bool )std::declval<T const &>(), (void )0 )));
838
+ DEBUG_COND (
839
+ reference_wrapper,
840
+ (typename std::enable_if<
841
+ std::is_same<typename T::type &,
842
+ decltype (std::declval<T const &>().get ())>::value,
843
+ int >::type)0 );
832
844
# define DEBUG_CON (n, ...) \
833
845
template <class T > \
834
846
struct debug_cond_ ##n : debug_bool_constant<__VA_ARGS__> {};
@@ -840,9 +852,6 @@ struct DEBUG_NODISCARD debug {
840
852
DEBUG_CON (error_code, std::is_same<T, std::errc>::value ||
841
853
std::is_same<T, std::error_code>::value ||
842
854
std::is_same<T, std::error_condition>::value);
843
- DEBUG_CON (reference_wrapper,
844
- std::is_same<typename T::type &,
845
- decltype (std::declval<T const &>().get ())>::value);
846
855
# if __cpp_char8_t
847
856
DEBUG_CON (unicode_char, std::is_same<T, char8_t >::value ||
848
857
std::is_same<T, char16_t >::value ||
@@ -1578,6 +1587,9 @@ struct DEBUG_NODISCARD debug {
1578
1587
oss << elapsed % 1000 ;
1579
1588
oss.flags (flags);
1580
1589
oss << ' ' ;
1590
+ # endif
1591
+ # if DEBUG_SHOW_THREAD_ID
1592
+ oss << ' [' << std::this_thread::get_id () << ' ]' << ' ' ;
1581
1593
# endif
1582
1594
char const *fn = loc.file_name ();
1583
1595
for (char const *fp = fn; *fp; ++fp) {
0 commit comments