Subject: Re: [boost] New, powerful way to use enable_if in C++0x
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-04-13 14:27:57
On Wed, Apr 13, 2011 at 11:02 AM, Matt Calabrese <rivorus_at_[hidden]> wrote:
> On Wed, Apr 13, 2011 at 1:35 PM, Jeffrey Lee Hellrung, Jr. <
> jeffrey.hellrung_at_[hidden]> wrote:
> > That would likely have issues with commas in the conditional, which I
> > think "double parens" could fix. That is, it's a problem unless all
> > compilers which support this use of SFINAE also support variadic
> > templates...
> I assume you mean variadic macros not variadic templates?
Yes, my mistake!
> Double parentheses
> would work fine when the compiler doesn't support variadic macros. Just
> define the macro as such, or similar:
> #define BOOST_ENABLE_IF( condition )\
> typename ::boost::enable_if\
> < typename ::boost::function_traits< void condition >::arg1_type\
> , int >::type = 0
Ah, clever, I hadn't seen or thought of that trick before.
Well that makes my comment null and void.
In fact it's possible to supply a simple variadic version when available and
> a regular macro similar to the one above when not, having the same macro
> name in either case without issue. You'd do this by making the variadic
> version check if the argument is parenthesized (which is possible with the
> preprocessor) and simply strip the parentheses if they are there. This
> allows backward compatibility by allowing people to specify either
> parenthesized or unparenthesized arguments.
Anyway, all of this parentheses hubbub is probably unecessary since as far
> as I know all compilers that have any experimental C++0x support already
> also support variadic macros (probably in part because of C99).
Yeah, I wasn't sure about this.
That covers any potential objections I had to the ENABLE_IF macro, and then
some! Thanks Matt.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk