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

Cannot parse std::tuple<bool> #42

Closed
guycook opened this issue Dec 13, 2022 · 2 comments
Closed

Cannot parse std::tuple<bool> #42

guycook opened this issue Dec 13, 2022 · 2 comments

Comments

@guycook
Copy link

guycook commented Dec 13, 2022

On MSVC, I'm unable parse fields like "member": [true] to a type std::tuple<bool> member. A minimal example is below

#include <iostream>
#include "json_struct.h"

struct TestInt {
  std::tuple<int32_t> member;
  JS_OBJ(member);
};

struct TestBool {
  std::tuple<bool> member;
  JS_OBJ(member);
};

int main(int argc, char** argv) {
  TestInt tiStruct;
  JS::ParseContext intContext(R"({ "member": [5] })");
  if (intContext.parseTo(tiStruct) == JS::Error::NoError) {
    std::cout << "Success, member is: " << std::get<0>(tiStruct.member) << std::endl;
  }
  else {
    std::cout << intContext.makeErrorString();
  }

  TestBool tbStruct;
  JS::ParseContext boolContext(R"({ "member": [true] })");
  if (boolContext.parseTo(tbStruct) == JS::Error::NoError) {
    std::cout << "Success, member is: " << std::get<0>(tbStruct.member) << std::endl;
  }
  else {
    std::cout << boolContext.makeErrorString();
  }
}

Output:

Success, member is: 5
Error ExpectedDelimiter:
{ "member": [true] }
                  ^

I'm not sure what the cause here is, all I can say from current investigation is that single item tuples of other basic types (number/string) still work, and tuples involving bools + other types work, e.g. std::tuple<bool, int> will parse fine if given [true, 2]

@jorgen
Copy link
Owner

jorgen commented Dec 14, 2022

Hi and thank you for your interest in json_struct. There was an error in a lookup table, making the end of token be the ] and not the e. Its fixed in the latest commit.

@jorgen jorgen closed this as completed Dec 14, 2022
@guycook
Copy link
Author

guycook commented Dec 14, 2022

Thanks for the quick resolution, can confirm this fixes the problem in my project as well as the test case. json_struct has been great so far, cheers!

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

2 participants