|
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 - Function templates with more than one declaration?
I'm building a simple atom (symbol, whatever) library for a project, but I'm
not really satisfied with my syntax for static atom literals. My template:
template atom(string name) {
static Atom myAtom;
static this() { myAtom = Atom(name); }
Atom atom() { return myAtom; } /* Hopefully this will be inlined, haven't
tested that yet... */
}
usage:
Atom name = atom!("name").atom;
The ideal, in my mind, would be to create Atom literals with the same
Atom("name") syntax usable for creating Atoms at runtime. I'm pretty sure that
won't be possible until templates can override functions, though. But I'd at
least like to get rid of that last spurious `.atom` at the end of the
declaration. Has anybody run into this situation before? What's the reason for
only allowing "Implicit Template Properties" when the template declares exactly
one member, anyway?
Apr 14 2008
Would a function template work in this case perhaps?
Atom atom(string name)(){
static Atom myAtom;
myAtom =3D Atom(name);
return myAtom;
}
Cheers,
Boyd
-------
On Mon, 14 Apr 2008 19:59:46 +0200, Brian Palmer <d brian.codekitchen.ne=
t> =
wrote:
Apr 14 2008
Brian Palmer wrote: Apr 14 2008
|