Skip to content

Member detector is not portable #166

Closed

Description

@glenfe

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.

Activity

  1. reopened this on Dec 30, 2015
  2. nlohmann commented on Jan 1, 2016

    @nlohmann
    Owner

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

  3. glenfe commented on Jan 1, 2016

    @glenfe
    Author

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

  4. nlohmann commented on Jan 1, 2016

    @nlohmann
    Owner

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

  5. glenfe commented on Jan 1, 2016

    @glenfe
    Author

    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;
    
  6. nlohmann commented on Jan 1, 2016

    @nlohmann
    Owner

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

  7. added a commit that references this issue on Jan 1, 2016
  8. added this to the milestone on Jan 1, 2016
  9. self-assigned this
    on Jan 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions