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

Member detector is not portable #166

Closed
glenfe opened this issue Dec 30, 2015 · 5 comments
Closed

Member detector is not portable #166

glenfe opened this issue Dec 30, 2015 · 5 comments
Assignees
Milestone

Comments

@glenfe
Copy link

glenfe commented Dec 30, 2015

Your has_mapped_type definition may be dependent on the C++ implementation providing int and char of different sizes. It is valid for an implementation to make them the same size.

You can remedy this by changing the return types to types which will be different sizes.

@glenfe glenfe closed this as completed Dec 30, 2015
@glenfe glenfe reopened this Dec 30, 2015
@nlohmann
Copy link
Owner

nlohmann commented Jan 1, 2016

Doesn't the C++ standard guarantee sizeof(char) == 1 and an int to have a width of at least 16 bits?

@glenfe
Copy link
Author

glenfe commented Jan 1, 2016

Yes? A C++ implementation can make sizeof(char) == sizeof(int) == 1 where CHAR_BIT is 16.

@nlohmann
Copy link
Owner

nlohmann commented Jan 1, 2016

I see... (Even though this would be really odd...)

@glenfe
Copy link
Author

glenfe commented Jan 1, 2016

Here's one possible fix:

template<typename C> static char (&test(...))[2];

Also, consider changing the next line to:

static constexpr bool value = sizeof(test<T>(0)) == 1;

@nlohmann
Copy link
Owner

nlohmann commented Jan 1, 2016

That's way more elegant. Thanks a lot for nitpicking on this. And Happy New Year!

nlohmann added a commit that referenced this issue Jan 1, 2016
@nlohmann nlohmann added this to the Release 1.0.1 milestone Jan 1, 2016
@nlohmann nlohmann self-assigned this Jan 1, 2016
@nlohmann nlohmann closed this as completed Jan 1, 2016
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