|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - Static opCall for templated structs
I often want to offer users a pretty way to create the templated structs=
I =
use, and I find it complexifying to have to place such prettification =
outside the struct itself. For instance:
struct foo(T)
{
T data;
static foo!(U) opCall(U)(U u)
{
foo!(U) result;
result.data =3D u;
return result;
}
}
Seeing as the static opCall is T agnostic, it would be nice to be able t=
o =
use it like:
auto f =3D foo(4);
However, that does of course not work, I need to write:
auto f =3D foo!(typeof(4))(4);
or place the static opCall outside the struct:
foo!(T) Foo(T)(T t)
{
foo!(T) result;
result.data =3D t;
return result;
}
struct foo(T)
{
T data;
}
Now, the first workaround is ugly, and the latter requires a different =
name for the constructing function, which is not quite as ugly, but stil=
l =
not as good as it should be.
...I'm starting to think this might be more of a feature request than a =
=
call for help, but oh well.
Is there a way to make this work in current D2.0, so that I can simply u=
se =
the first syntax?
--Simen
Apr 15 2008
Simen Kjaeraas wrote: Apr 15 2008
|