ericniebler / meta

A tiny metaprogramming library
Boost Software License 1.0
302 stars 47 forks source link

Replace std::is_void by std::decay #72

Closed Little-Flower-171 closed 5 years ago

Little-Flower-171 commented 5 years ago

Currently std::is_void is used as an example of type trait. But std::is_void contains ::value instead of ::type, thus not fitting with the definition of "trait."

CaseyCarter commented 5 years ago

Per [meta.unary]/2:

Each of these templates shall be a Cpp17UnaryTypeTrait ([meta.rqmts]) with a base characteristic of true_­type if the corresponding condition is true, otherwise false_­type.

true_type and false_type are specializations of integral_constant. Per the class synopsis in [meta.help], specializations of integral_constant have both a member value, with the same value as the non-type template parameter, and a member type that is an alias for the same specialization of integral_constant.

So yes, is_void is a trait.

Little-Flower-171 commented 5 years ago

Hi @CaseyCarter, Thank you for your quick reply and thank you for your patience! I just realized what a severe mistake I just made in that I forgot the ::type member of std::integral_constant, in turn std::is_void. This shows that I did not think of it thoroughly before I judge it as a "mistake." I apologize for that. On the other hand, I still suggest that std::decay (or std::add_*, std::remove_*, std::make_[un]signed, std::aligned_storage, std::aligned_union, std::common_type, std::[basic_]common_reference, std::underlying_type, std::invoke_result (or previously std::result_of,) std::void_t, std::type_identity, std::enable_if, std::conditional, etc.; I chose std::decay simply because it first bumped up in my mind) makes a better example, cuz:

  1. AFAIK the primary use (i.e. "return value") of std::is_void is ::value instead of ::type, which is merely for convenience, whereas most traits use ::type as the primary "return value," with or without a (secondary) ::value. Opting for std::decay (or ...) may better demonstrate this idea.
  2. It may not be that obvious at a first glance that the reason std::is_void is a (type) trait is that it has ::type rather than that ::value also fulfills the condition of a trait, cuz most people (like stupid and despicable me!) may be more alert to the ::value of it.

This is purely a suggestion. If it seems too silly for you, just discard it! :smile: Have a nice day and keep on good working!