typedef alternative
Yao G.
nospamyao at gmail.com
Sat Aug 14 17:47:44 PDT 2010
Hello.
Is there an alternative to typedef? I need to define three structs that
have exactly the same methods and properties, yet represent different
stuff.
Example:
---
struct Foo
{
this( int f ) {
_foo = f;
}
int asNumber() {
return _foo;
}
private immutable int _foo;
}
// This should be typedef, but as it's going to be deprecated...
alias Foo Year;
alias Foo Month;
alias Foo Day;
void bar( Year y, Month m, Day d ) {
// ...
}
// This should compile, obviously.
bar( Year(2010), Month(8), Day(14) );
// But this shouldn't
bar( Day(1), Year(1), Month(1) );
---
So, what options do I have? I know that typedef is scheduled to
deprecation, so I would like to know if there's something else.
--
Yao G.
More information about the Digitalmars-d-learn
mailing list