This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Suggestions for convenience aliases in <type_traits>
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Daniel Krügler <daniel dot kruegler at gmail dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 11 Jun 2014 11:14:55 +0100
- Subject: Re: Suggestions for convenience aliases in <type_traits>
- Authentication-results: sourceware.org; auth=none
- References: <20140610103036 dot GI30729 at redhat dot com> <CAGNvRgDWicqfYQfh3L=ubuhnBYbM0G7_+_k5GTwXk6E5VRdbbw at mail dot gmail dot com> <20140610111702 dot GJ30729 at redhat dot com> <CAGNvRgCeUqsuDH-4X17S3re+9LD-jkg6MGj3z-RCTDRiGBuSpw at mail dot gmail dot com>
On 11/06/14 07:53 +0200, Daniel Krügler wrote:
2014-06-10 13:17 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
On 10/06/14 12:47 +0200, Daniel Krügler wrote:
Is that reasonable?
Personally I consider these as bad examples for alias templates and
suggest to provide corresponding class templates instead (such __and,
__or, __not).
Do you mean like this?
template<typename _If, typename _Then, typename _Else>
struct __conditional_
: conditional<_If::value, _Then, _Else>
{ };
With that I lose the convenience of the C++14 '_t' aliases and have to
write 'typename' and '::type' every time I use it.
Or do you mean like this:
template<typename _If, typename _Then, typename _Else>
struct __conditional_t_
: conditional<_If::value, _Then, _Else>::type
{ };
In that case doesn't it also evaluate the prediate immediately, and so
has no advantage over the alias template.
[Apologies for my late response, but I was completely bound by other things]
The latter. There is an advantage of the second form, because you
combine it like this
SomeTemplate<__conditional_t_<X, Y, Z>>
this would not necessarily instantiate the __conditional_t_ class
template (but it would for the alias). This situation becomes
relevant, if this
__conditional_t_<X, Y, Z>
is part of a potentially unevaluated part of template parameters.
OK, thanks for the explanation. In the cases I was thinking of using
this there are usually no unevaluated parameters, but I agree that if
we are going to add it to <type_traits> then your suggestion is more
flexible and has advantages for other use cases (e.g. nested uses of
std::conditional inside std::conditional).
So if we were to use that design, I think the '_t_' suffix is not
appropriate, but we could have:
template<typename _If, typename _Then, typename _Else>
struct __conditional_
: conditional<_If::value, _Then, _Else>
{ };
And then an alias for the cases where it isn't potentially unevaluated
and immediate instantiation is OK:
template<typename _If, typename _Then, typename _Else>
using __conditional_t_ = typename
__conditional_<_If::value, _Then, _Else>::type;