Skip to content

Reading numbers as string leads to reading error #1533

Answered by stephenberry
Rooib asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for your question. The number option mostly exists to facilitate the glz::number wrapper that allows you to individually define which std::string fields should be treated as number.

Your example shows that the error code is really unhelpful, and so I've updated the code in #1535 to return a parse_number_failure if the input is not a number.

In your case, setting the .number = true option globally tells Glaze to parse all types like std::string as numbers.

What you want is to use a meta to selectively parse only the strings that you want to be numbers:

template <>
struct glz::meta<my_struct>
{
   using T = numbers_as_strings2;
   static constexpr auto value = object("i", number<&T::…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Rooib
Comment options

Answer selected by Rooib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants