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

Feature request: Add helper macros #139

Closed
hg-zt opened this issue Oct 15, 2020 · 4 comments
Closed

Feature request: Add helper macros #139

hg-zt opened this issue Oct 15, 2020 · 4 comments

Comments

@hg-zt
Copy link

hg-zt commented Oct 15, 2020

In nlohmann/json we have https://github.com/nlohmann/json#simplify-your-life-with-macros
so that I could simply define both serializer and deserializer in one line:

namespace my_ns {

struct MyType {
  int some_value;
  OtherSerializableType some_obj;
}

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MyType, some_value, some_obj);
}

which makes it possible to convert from/to

{
   "some_value": 1,
   "some_obj": { ... }
}

I'd like to have similar macros to generate into_toml and from_toml for simple structs. Something like TOML11_DEFINE_NON_INTRUSIVE.

@ToruNiina
Copy link
Owner

Sounds nice. I think I can implement it quickly.
But, because of the current implementation, the usage would be slightly different from the code shown.

@ToruNiina
Copy link
Owner

I'm struggling with the difference in the preprocessor implementation between gcc/clang and MSVC. If you are using gcc/clang, here is the working code. If you are using MSVC, please wait a bit more.

https://github.com/ToruNiina/toml11/blob/auto-conversion-macro/toml/macros.hpp

@glebm
Copy link

glebm commented Mar 21, 2021

Looks like Microsoft added a preprocessor flag that enables well-behaved __VA_ARGS__ in the recent versions of their compiler, /Zc:preprocessor:

This option enables a token-based preprocessor that conforms to C99 and C++11 and later standards.

Perhaps toml11 could require the flag to be set?

@ToruNiina
Copy link
Owner

Thank you very much @glebm ! It works!

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

3 participants