C++ Logo

std-discussion

Advanced search

Re: Concept equivalents of type traits.

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Wed, 23 Aug 2023 21:47:30 -0500
On Wed, 23 Aug 2023 at 21:20, AC Demiralp via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> Dear all,
>
> this is my first post to this group, and it might not even be the correct
> group to post to. Please correct me if I'm wrong.
>
> The following code creates concept equivalents of every type trait that
> evaluates to a bool:
>
> https://github.com/acdemiralp/type_trait_concepts/blob/main/include/std/experimental/type_trait_concepts.hpp
>
> This is useful to constrain templates using a simple syntax, without
> relying on the more verbose requires keyword. To me, it is the cleanest way
> to use concepts. A toy example:
> template <integral_c type>
> auto function_only_accepting_integral_types() { ... }
>

std::integral is already a concept.

Many of the other cases are either already concepts with semantics
identical to the respective type trait, or with a different implementation
better suited to use as a concept: same_as is bidirectional for
subsumption, derived_from is reversed from is_base_of (since bases are a
closed set), constructible_from also checks destructibility. The concepts
library is carefully designed to not just be a transcription of the traits
library.

For those traits that don't have corresponding concepts (I would like to
see an invocable_r alongside invocable) there's usually work to be done to
ensure the concept is written in the most appropriate way.

Perhaps there's space for a facility that wraps an existing type trait as a
concept, but I'm not sure whether that needs to be standardized:

template<class C, template<class...> class T, class... U>
concept satisfying = T<C, U...>::value;


Do you think this is useful? Useful enough to be considered into the
> standard?
>
> I will build a more complete motivation/proposal with non-toy examples if
> you think its worth it.
>
> Good day.
>
> Best regards,
> Ali Can Demiralp
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2023-08-24 02:47:44