MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / Formatter

Function Formatter

12.18-constevalParmCheck0/main.cpp:37–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35
36template<typename T, class... Args>
37void Formatter(string& buffer,
38 std::string_view v,
39 const T& t,
40 const Args&... args)
41{
42 using PT = std::remove_cv_t<T>;
43
44 if constexpr(std::is_same_v<int, PT>) {
45 if('d' != v[0]) { throw int{3}; }
46 buffer.append(itoa(t));
47
48 } else if constexpr(std::is_convertible_v<PT, std::string_view>) {
49 if('s' != v[0]) { throw int{4}; }
50 buffer.append(t);
51
52 } else {
53 throw int{6};
54 }
55
56 v.remove_prefix(1);
57
58 if constexpr(sizeof...(Args) > 0) { Formatter<Args...>(buffer, v, args...); }
59}
60
61template<class... Args>
62string format(std::string_view fmt, const Args&... args);

Callers 1

formatFunction · 0.70

Calls 1

itoaFunction · 0.70

Tested by

no test coverage detected