References in D
Jonathan M Davis
jmdavisProg at gmx.com
Sun Sep 16 17:06:09 PDT 2012
On Sunday, September 16, 2012 12:08:52 Peter Alexander wrote:
> My favourite C++ wtf:
>
> struct Foo
> {
> template <int x, int y> int fun(bool c) { return c ? x : y; }
> };
>
> struct Bar
> {
> int fun;
> };
>
> template <typename T>
> int madness()
> {
> return T().fun<1, 2>(true);
> }
>
> The WTF: madness<Foo> doesn't compile, but madness<Bar> does
> (with a warning).
Ouch. I assume that that's due to the two-pass template lookup nonsense (or
whatever the exact name is), which means that that probably won't even behave
the same across compilers, since not all compilers implement that the same way
(most notably, Microsoft specifically echoues it in favor of a scheme that
makes more sense, though it's still a bad idea, since it's non-standard).
Thank goodness that D didn't follow C++'s example on _that_ one.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list