Is this is bug or not?

Sean Kelly sean at f4.ca
Fri Mar 17 14:03:10 PST 2006


Don Clugston wrote:
> Thomas Kuehne wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Victor Nakoryakov schrieb am 2006-03-11:
>>> Hi all,
>>>
>>> Here is a snipet:
>>>
>>> import std.stdio;
>>>
>>> struct A(T, T x0)
>>> {
>>> T x = x0;
>>> }
>>>
>>> int main(char[][] args)
>>> {
>>> alias A!(int, 8) Ai; // test.d(11)
>>> Ai ai;
>>> writefln(ai.x);
>>> return 0;
>>> }
> 
> If that had worked, it would have been a new feature. You're obtaining a 
> type AND a value! Note that value parameters only work for basic types 
> and char[]. It would be very cool, though -- it would enable a lot of 
> code reuse for metaprogramming.
> 
> For example, pow!(real z, int n) and pow!(creal z, int n) would be able 
> to share a common implementation. The fact that they can't has been 
> bugging me for some time.

For what it's worth, this is legal in C++:

     #include <iostream>

     template<class T, T x>
     struct S
     {
         static const T val = x;
     };

     int main()
     {
         int x = S<int,5>::val;
         std::cout << x << '\n';
     }

Sean



More information about the Digitalmars-d mailing list