Skip to content

Commit

Permalink
Fix compilation error when using more than 11 arguments with scn::scan
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed May 18, 2024
1 parent 52db487 commit 9894e84
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
13 changes: 9 additions & 4 deletions include/scn/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -5168,9 +5168,14 @@ constexpr size_t encode_types_impl()
template <typename CharT, typename... Ts>
constexpr size_t encode_types()
{
static_assert(sizeof...(Ts) < (1 << packed_arg_bits));
return sizeof...(Ts) |
(encode_types_impl<CharT, Ts...>() << packed_arg_bits);
if constexpr (sizeof...(Ts) < (1 << packed_arg_bits)) {
return sizeof...(Ts) |
(encode_types_impl<CharT, Ts...>() << packed_arg_bits);
}
else {
SCN_EXPECT(false);
SCN_UNREACHABLE;
}
}

template <typename Arg>
Expand Down Expand Up @@ -5530,7 +5535,7 @@ class basic_scan_args {
: m_desc{desc}, m_values{values}
{
}
constexpr basic_scan_args(size_t desc, basic_scan_args<Context>* args)
constexpr basic_scan_args(size_t desc, basic_scan_arg<Context>* args)
: m_desc{desc}, m_args{args}
{
}
Expand Down
31 changes: 29 additions & 2 deletions tests/unittests/scan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ TEST(ScanTest, DeconstructedTimestamp)
}
TEST(ScanTest, DeconstructedTimestamp2)
{
auto res = scn::scan<int, int, int, int, int>(
"2024-03-23T09:20:33.576864", "{:4}-{:2}-{:2}T{:2}:{:2}:");
auto res = scn::scan<int, int, int, int, int>("2024-03-23T09:20:33.576864",
"{:4}-{:2}-{:2}T{:2}:{:2}:");
ASSERT_TRUE(res);
EXPECT_EQ(std::get<0>(res->values()), 2024);
EXPECT_EQ(std::get<1>(res->values()), 3);
Expand All @@ -205,3 +205,30 @@ TEST(ScanTest, DeconstructedTimestamp2)
EXPECT_EQ(std::get<4>(res->values()), 20);
EXPECT_STREQ(res->range().data(), "33.576864");
}

TEST(ScanTest, LotsOfArguments)
{
auto res = scn::scan<int, int, int, int, int, int, int, double>(
"1 2 3 4 5 6 7 8.9", "{} {} {} {} {} {} {} {}");
ASSERT_TRUE(res);
auto [a1, a2, a3, a4, a5, a6, a7, a8] = res->values();
EXPECT_EQ(a1, 1);
EXPECT_EQ(a2, 2);
EXPECT_EQ(a3, 3);
EXPECT_EQ(a4, 4);
EXPECT_EQ(a5, 5);
EXPECT_EQ(a6, 6);
EXPECT_EQ(a7, 7);
EXPECT_DOUBLE_EQ(a8, 8.9);
}
TEST(ScanTest, EvenMoreArguments)
{
auto res = scn::scan<int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int, int>(
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 "
"27 28 29 30 31 32 33",
"{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} "
"{} {} {} {} {} {} {} {} {} {}");
ASSERT_TRUE(res);
}

0 comments on commit 9894e84

Please sign in to comment.