Skip to content

Commit 01be679

Browse files
authored
Merge pull request #212 from elbeno/add-num-fmt-specs
✨ Add `num_fmt_specifiers`
2 parents a1c783d + da38967 commit 01be679

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/stdx/ct_format.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ constexpr auto ct_format = [](auto &&...args) {
229229
return format_result{detail::convert_output<result.str.value, Output>(),
230230
result.args};
231231
};
232+
233+
template <ct_string Fmt>
234+
constexpr auto num_fmt_specifiers =
235+
detail::count_specifiers(std::string_view{Fmt});
232236
} // namespace v1
233237
} // namespace stdx
234238

test/ct_format.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,8 @@ TEST_CASE("format multiple mixed arguments with different type",
218218
string_constant>(),
219219
stdx::make_tuple(42, "B"sv)});
220220
}
221+
222+
TEST_CASE("num fmt specifiers", "[ct_format]") {
223+
static_assert(stdx::num_fmt_specifiers<"{}"> == 1u);
224+
static_assert(stdx::num_fmt_specifiers<"{} {}"> == 2u);
225+
}

0 commit comments

Comments
 (0)