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

Library Concepts? #13

Open
vector-of-bool opened this issue Apr 14, 2021 · 2 comments
Open

Library Concepts? #13

vector-of-bool opened this issue Apr 14, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@vector-of-bool
Copy link

Is there an intention to add library concepts in place of the current named requirements?

There's admittedly some challenges in doing so, but I enjoy the benefits of clearer error messages and simpler overload sets.

e.g.

template <typename E>
concept encoding =
    (requires() {
        // One state type
        typename E::state;
    } ||
    requires() {
        // OR distinct state types
        typename E::encode_state;
        typename E::decode_state;
    }) &&
    requires(E encoding,
             encode_state_t<E> enc_state,
             decode_state_t<E> dec_state,
             range_archetype<convertible_to_archetype<code_point_t<E>>> cp_in_range,
             range_archetype<convertible_to_archetype<code_unit_t<E>>> cu_in_range,
             range_archetype<assignable_from_archetype<code_point_t<E>>> cp_out_range,
             range_archetype<assignable_from_archetype<code_unit_t<E>>> cu_out_range,
             handler_archetype handler) {
        { E::max_code_points } -> convertible_to<size_t>;
        { E::max_code_units } -> convertible_to<size_t>;
        { encoding.encode_one(cp_in_range, cu_out_range, handler, enc_state) };
        { encoding.decode_one(cu_in_range, cp_out_range, handler, dec_state) };
    };

Such a definition won't be perfect because we can't be certain that encode_one() will be valid without knowing the exact range type that will be used until we actually call it, but one can make a very close approximation using concept archetypes.

@ThePhD
Copy link
Contributor

ThePhD commented Apr 14, 2021

This is meant to be a C++17 library so I can't really write concepts and I'm not quite ready to take the pain of "Write a Macro Layer to separate concepts from typical SFINAE and then use that".

That being said, I'm definitely going to be writing this kind of thing for the Standards Paper, so it's probably good to at least put it in the documentation somewhere.

@ThePhD
Copy link
Contributor

ThePhD commented Apr 14, 2021

Hell, I can probably put some of this into a cxx20/ subfolder so that at least people can include that directory intentionally and use some of these concepts directly. I can also probably "promote" some of those concept checks into the global namespace and make them is_..._v things by-default for C++17. Probably won't help too much with the overload resolution shenanigans...

@ThePhD ThePhD self-assigned this Apr 22, 2021
@ThePhD ThePhD added the enhancement New feature or request label Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants