Template namespaces - Obsolete?
Bill Baxter
dnewsgroup at billbaxter.com
Wed Sep 19 12:40:39 PDT 2007
Janice Caron wrote:
> Now that we can do:
> class A(T);
> struct A(T);
> union A(T);
> T func(T)(T x);
> static int func(int n);
> ...
> etc.
>
> Is there any need, any more, for the old fashioned
>
> template t(T)
> {
> int f();
> int g();
> }
Mixins as you mention.
That also includes mixins as a work around for lack of inner namespaces.
I doubt macros will ever be able to create new namespaces.
Also it's just handy for cases where you have a few functions that all
share the same collection of derived types etc.
template AutoRepair(CarType) {
alias CarType.wheel_type Wheel;
alias CarType.body_type Body;
alias CarType.engine_type Engine;
alias Engine.fuel_type Fuel;
alias CarType.transmission_type Transmision;
alias CarType.manufacturer manufacturer;
// returns the new Engine
Engine fix_engine(CarType car, Engine replacement_part) { ...
}
// returns the new body
Body repair_body(CarType car, Body replacement_part) { ...
}
/// etc...
}
--bb
More information about the Digitalmars-d
mailing list