Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabulist compiler does not build with C++ 20 #14

Closed
Pheubel opened this issue Sep 10, 2022 · 0 comments
Closed

Fabulist compiler does not build with C++ 20 #14

Pheubel opened this issue Sep 10, 2022 · 0 comments

Comments

@Pheubel
Copy link

Pheubel commented Sep 10, 2022

As discussed on the NovelRT discord, currently there is code that does not compile in C++ 20, this has to do with a behavior change in std::accumulate.

nlohmann::json result = std::accumulate(
values.begin(), values.end(),
nlohmann::json{},
[is_array](nlohmann::json& result,
decltype(values)::const_reference value)
{
if (is_array)
{
result.push_back(value.second);
}
else
{
std::visit([&result, &value = value.second](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, double>)
{
result[std::to_string(arg)] = value;
}
else if constexpr (std::is_same_v<T, std::string>)
{
result[arg] = value;
}
}, value.first);
}
return result;
});

As mentioned in discord, passing in nlohmann::json result as a value instead of a reference in the lambda function seems like the best way forward, it builds on both C++ 17 and C++ 20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant