Skip to content

Commit 7e9d4dd

Browse files
committed
Add CONFIG_FREQUENCY_STD_FORMAT flag
1 parent 7be7c0b commit 7e9d4dd

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
menu "Frequency Library"
2+
3+
config FREQUENCY_STD_FORMAT
4+
bool "Enable std::format support"
5+
default y
6+
help
7+
Include <format> and provide std::formatter specializations
8+
for frequency types. Disable if <format> is unavailable or
9+
undesired.
10+
11+
endmenu

include/frequency/frequency.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
#include <limits>
1313
#include <ratio>
1414
#include <string>
15+
#ifndef CONFIG_FREQUENCY_STD_FORMAT
1516
#if __has_include(<format>) && defined(__cpp_lib_format)
17+
#define CONFIG_FREQUENCY_STD_FORMAT 1
18+
#else
19+
#define CONFIG_FREQUENCY_STD_FORMAT 0
20+
#endif
21+
#endif
22+
23+
#if CONFIG_FREQUENCY_STD_FORMAT
1624
#include <format>
1725
#endif
1826
#include <assert.h>
@@ -1130,7 +1138,7 @@ struct common_type<freq::frequency<Rep1, Precision1>, freq::frequency<Rep2, Prec
11301138
using type = freq::frequency<std::common_type_t<Rep1, Rep2>, common_precision>;
11311139
};
11321140

1133-
#if __has_include(<format>) && defined(__cpp_lib_format)
1141+
#if CONFIG_FREQUENCY_STD_FORMAT
11341142
template<>
11351143
struct formatter<freq::millihertz> {
11361144
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }

0 commit comments

Comments
 (0)