diff --git a/test/scan.h b/test/scan.h index 59f41f77..2e3f8f7a 100644 --- a/test/scan.h +++ b/test/scan.h @@ -10,7 +10,7 @@ #include #include -#include "fmt/format.h" +#include "fmt/format-inl.h" FMT_BEGIN_NAMESPACE namespace detail { @@ -555,25 +555,45 @@ void vscan(detail::scan_buffer& buf, string_view fmt, scan_args args) { auto h = detail::scan_handler(fmt, buf, args); detail::parse_format_string(fmt, h); } -} // namespace detail -template -auto make_scan_args(T&... args) -> std::array { - return {{args...}}; +template +void make_args(std::array&, std::tuple&) {} + +template +void make_args(std::array& args, + std::tuple& values) { + using element_type = typename std::tuple_element>::type; + static_assert(std::is_same, element_type>::value, + ""); + args[I] = std::get(values); + make_args(args, values); } +} // namespace detail template class scan_data { private: std::tuple values_; public: + scan_data() = default; scan_data(T... values) : values_(std::move(values)...) {} auto value() const -> decltype(std::get<0>(values_)) { return std::get<0>(values_); } + + auto make_args() -> std::array { + auto args = std::array(); + detail::make_args<0>(args, values_); + return args; + } }; +template +auto make_scan_args(T&... args) -> std::array { + return {{args...}}; +} + class scan_error {}; // A rudimentary version of std::expected for testing the API shape. @@ -606,10 +626,9 @@ auto scan_to(string_view input, string_view fmt, T&... args) template auto scan(string_view input, string_view fmt) -> scan_result { - static_assert(std::is_same, T>::value, ""); - auto value = T(); - scan_to(input, fmt, value); - return scan_data(std::move(value)); + auto data = scan_data(); + vscan(input, fmt, data.make_args()); + return data; } template