Boost logo

Boost :

Subject: Re: [boost] Need help with workaround for MSVC bug
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-09-17 19:44:01


On Thu, Sep 17, 2009 at 4:27 PM, Jeffrey Hellrung <jhellrung_at_[hidden]> wrote:
> Emil Dotchevski wrote:
>>
>> On MSVC, the following correct code produces error C2896: 'void
>> operator ||(T,void (__cdecl *)(tag<X>))' : cannot use function
>> template 'void bar(tag<X>)' as a function argument.
>>
>> struct foo { };
>>
>> template <int X>
>> struct tag { };
>>
>> template <int X>
>> void bar( tag<X> ) { }
>>
>> template <class T,int X>
>> void operator||(T, void(*)(tag<X>)) { }
>>
>> int main()
>> {
>>  foo()||bar<1>;
>> }
>>
>> My goal is to have an operator|| overload that deduces tag<X>
>> implicitly, but without using parenthesis, that is, foo()||bar<1>()
>> wouldn't be satisfactory. Doesn't seem possible, but still I decided
>> to ask. Any ideas?
>
> What about statically initialized pod objects, like the placeholder
> arguments in phoenix or lambda?
>
> I guess that only works if you have a (reasonably) bounded set from which X
> can come from...

You mean something like _1, _2, etc? Yes that could work but it's not
ideal. Also, I found some other curiosities, like the fact that this
declaration for op|| works:

template <class T>
void operator||(T, void(*)(tag<1>)) { }

Presumably, I could provide K overloads instead of using the X
template argument. That's silly, but it has the same limitations of
the _1, _2 approach and has the benefit of not being silly on other
compilers.

I've also found that my original code works fine if I overload the
comma operator instead of ||. Go figure...

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk