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

BSerializer::Serializable is not satisfied by std::vector<bool> #3

Closed
brendanlynn opened this issue Jul 29, 2024 · 2 comments · Fixed by #4
Closed

BSerializer::Serializable is not satisfied by std::vector<bool> #3

brendanlynn opened this issue Jul 29, 2024 · 2 comments · Fixed by #4
Assignees
Labels
bug Something isn't working

Comments

@brendanlynn
Copy link
Owner

brendanlynn commented Jul 29, 2024

BSerializer::Serializable is not satisfied by std::vector<bool>. More specifically, the type BSerializer::Collection, which BSerializer::Serializable indirectly references, is not satisfied by std::vector<bool>.

This is not the case with other std::vector<...>s, such as std::vector<int> or std::vector<uint8_t>. To the extent of my current understanding, it only happens with element type bool.

@brendanlynn brendanlynn added the bug Something isn't working label Jul 29, 2024
@brendanlynn
Copy link
Owner Author

This also applies to std::list<bool>, which does not satisfy BSerializer::Collection, while other variations such as std::list<int> or std::list<std::pair<int, const int>> do.

@brendanlynn
Copy link
Owner Author

The current code for the concept BSerializer::Collection is as follows, with comment annotation:

template <typename _T>
concept Collection = requires() {
    typename _T::value_type;
    typename _T::size_type;
    typename _T::const_iterator;

    requires std::unsigned_integral<typename _T::size_type>;

    requires requires (const _T Obj) {
        { Obj.size() } -> std::same_as<typename _T::size_type>;
        { Obj.cbegin() } -> std::same_as<typename _T::const_iterator>;
        { Obj.cend() } -> std::same_as<typename _T::const_iterator>;
    };

    //This condition is false on element type of bool:
    requires requires(const typename _T::const_iterator CIt) {
        { *CIt } -> std::same_as<const typename _T::value_type&>;
    };

    requires requires(typename _T::const_iterator CIt) {
        { ++CIt } -> std::same_as<typename _T::const_iterator&>;
        { CIt++ } -> std::same_as<typename _T::const_iterator>;
    };

    requires requires(const typename _T::const_iterator CIt1, const typename _T::const_iterator CIt2) {
        { CIt1 == CIt2 } -> std::same_as<bool>;
        { CIt1 != CIt2 } -> std::same_as<bool>;
    };

    //This condition is also false on element type of bool:
    requires requires(const typename _T::value_type* const P1, const typename _T::value_type* const P2) {
        _T{ P1, P2 };
    };
};

@brendanlynn brendanlynn self-assigned this Jul 29, 2024
@brendanlynn brendanlynn linked a pull request Jul 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant