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

Unable to extract boolean value in numberic format #987

Closed
k-nero opened this issue Mar 1, 2024 · 1 comment
Closed

Unable to extract boolean value in numberic format #987

k-nero opened this issue Mar 1, 2024 · 1 comment

Comments

@k-nero
Copy link

k-nero commented Mar 1, 2024

Version of Boost
1.84.0

Code:

class X
{
public:
	X() : x(false) {}
	X(bool x) : x(x) {}
protected:
	bool x;
	BOOST_DESCRIBE_CLASS(X, (), (), (x), ())
};

int main()
{
	try
	{
		boost::json::value jv = { { "x", 0 } };
		auto a = boost::json::value_to<X>(jv);
	}
	catch (std::exception const& e)
	{
		std::cerr << "Error: " << e.what() << std::endl;
	}
}

This would faild and throw an exception: Error: value is not boolean

@grisumbras
Copy link
Member

Yes. This is by design. 0 is not a boolean value.

@k-nero k-nero closed this as completed Mar 1, 2024
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