-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[C++] Simplify type_traits.h #38204
Comments
We can document them (!) with a publishable version of this:
After I laid them out in the graph above there are only a few things I would change because I think the predicates actually follow a neat hierarchy:
Sometimes we want to test whether a type belongs to an explicit definition of a set and sometimes we want to test for a property. There are uses for both. This is a classic debate in Logic [1]. One problem with predicates that test for a property (extensional equality) is that the set of types keeps growing and we can't know for sure existing kernel implementations outside of our control are not assuming other properties from the predicates we currently provide. If we had a "has offsets" predicate, we would be tempted to include list-views on that, but almost surely that would make code written based on that property break because that code probably also assumes that the offsets would be sorted. We would end-up with a confusing "has offsets" in the codebase with a big warning telling people that it can't be extended to list-views. I think a good contract to honor in |
We could, but I disagree that this is the best direction to take
Could you give an example? I'm not convinced this is a useful distinction. If we explicitly define a set, when would we do so other than to enumerate the elements which have a property?
This is a fair point, but I'd say that it would be sufficient to deprecate the existing traits to give users an opportunity to update. |
Most of predicates in Example of properties:
This is why I would prefer to keep |
Proposal: start an experimental type_traits.h alternative (private in the beginning), adopt it in kernels, evaluate the result, and compare it with the current situation and only then decide to deprecate |
@felipecrv is that visual available in the source or documentation today? It is a fantastic reference |
@WillAyd not yet because I haven't figured out an effortless way of keeping it up to date. I will update this gist [1] when I update it again. [1] https://gist.github.com/felipecrv/3c02f3784221d946dec1b031c6d400db |
Describe the enhancement requested
We have a large number of type traits in
type_traits.h
which are used inconsistently and whose relationships and specific semantics are not really documented. These have been added ad-hoc as they were needed rather than systematically laid out. I think instead of trying to construct them in reflection the class hierarchy ofDataType
is only indirectly useful; what we actually use these to check for isstd::string_view
or are they numeric?So I think it'd be more valuable to replace ambiguous traits like
is_binary_like
andis_string_like
altogether, perhaps withis_string_view_visitable
andis_utf8
.Nice to haves:
At the same time, traits like
is_floating_type
could be upgraded to c++17 variable templates. These are partially specializable as with class templates, so we wouldn't lose any flexibility by rewriting to:It'd also be nice to unify the template traits with the function traits (which taking a
Type::type
or aconst DataType&
and returnbool
), so that where one is available the other is definitely present (similar to the wayenable_if
specializations are currently always present).The
enable_if
specializations are handy but could be replaced byif constexpr
in many places.Component(s)
C++
The text was updated successfully, but these errors were encountered: