Topic: Getting rid of "typename ...::type" for some cases?
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Mon, 1 Feb 2010 11:38:08 CST Raw View
I wonder whether it would be possible to get rid of "typename <tmp>::type"
for the most common cases (enable_if (?))
template<bool C, typename T = void>
using enable_if = typename enable_if<C, T>::type;
Does that allow the following?
template<typename T>
enable_if<is_pointer<T>::value> f();
If it does, has it been considered to make it that way?
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Tue, 2 Feb 2010 00:46:29 CST Raw View
On 1 Feb., 18:38, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
> I wonder whether it would be possible to get rid of "typename <tmp>::type"
> for the most common cases (enable_if (?))
>
> template<bool C, typename T = void>
> using enable_if = typename enable_if<C, T>::type;
>
> Does that allow the following?
>
> template<typename T>
> enable_if<is_pointer<T>::value> f();
>
> If it does, has it been considered to make it that way?
I don't think that you can reintroduce the name enable_if,
but except for this the approach looks both feasible and
nice to me. Regarding your second question: I don't
think that it has been considered - nice idea.
- Daniel
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Mon, 8 Feb 2010 22:27:41 CST Raw View
Daniel Kr gler wrote:
> On 1 Feb., 18:38, "Johannes Schaub (litb)" <schaub-johan...@web.de>
> wrote:
>> I wonder whether it would be possible to get rid of "typename
>> <tmp>::type" for the most common cases (enable_if (?))
>>
>> template<bool C, typename T = void>
>> using enable_if = typename enable_if<C, T>::type;
>>
>> Does that allow the following?
>>
>> template<typename T>
>> enable_if<is_pointer<T>::value> f();
>>
>> If it does, has it been considered to make it that way?
>
> I don't think that you can reintroduce the name enable_if,
> but except for this the approach looks both feasible and
> nice to me. Regarding your second question: I don't
> think that it has been considered - nice idea.
>
I think were it would be most useful is for std::identity. I find myself
using it alot, and allowing for shorter typing would be very nice. I'm
thinking of "alias" or something similar:
alias<char[1]> &f();
operator alias<void()>*();
template<typename T> T implicit_cast(alias<T> t) { return t; }
f(alias<unsigned char>());
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]