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

Does it support std::optional or boost::optional out of the box ? #677

Closed
vricosti opened this issue Feb 9, 2022 · 11 comments · Fixed by #769
Closed

Does it support std::optional or boost::optional out of the box ? #677

vricosti opened this issue Feb 9, 2022 · 11 comments · Fixed by #769

Comments

@vricosti
Copy link

vricosti commented Feb 9, 2022

Hello,

Does it support simple json conversion from std::optional<std::string> for instance ? When I test I get some errors.
Thanks

@vricosti vricosti changed the title std::optional or boost::optional Does it support std::optional or boost::optional out of the box ? Feb 9, 2022
@grisumbras
Copy link
Member

Not yet, but it will be most likely added in the future.

@toonetown
Copy link

I would like to request this as well. Is this something that is being actively looked at, or is it something where a PR would be welcomed?

@vinniefalco
Copy link
Member

What would "supporting optional" look like? Can you please give example code (using types from Boost.JSON)?

@toonetown
Copy link

As I am looking into boost::json more, I think it might be achievable outside the library by treating null values as an optional with no value. Perhaps supporting it inside the boost::json library is not necessary nor desirable.

@pdimov
Copy link
Member

pdimov commented Aug 3, 2022

What would "supporting optional" look like?

Default implementations of value_from and value_to for std::optional<T>.

@grisumbras
Copy link
Member

To be honest, the hardest part of implementing this feature is determining a good trait for what is and isn't an optional. I.e. is checking that the type is std::optional<T> good enough? I suspect people would expect boost::optional to be supported too.

@madmongo1
Copy link
Collaborator

Optionals have the member functions .has_value() and .get()
That’s probably enough?

@grisumbras
Copy link
Member

Yeah, could work

@pdimov
Copy link
Member

pdimov commented Aug 3, 2022

boost::optional can be supported on the boost::optional side. There's no need for JSON to know about all the optionals.

@NexusHero
Copy link

Is there a timeline for this feature?

@grisumbras
Copy link
Member

Most likely before the next Boost release (December)

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

Successfully merging a pull request may close this issue.

7 participants