On Saturday, 14 March 2015 at 15:45:30 UTC, Charles Cooper wrote:
I think I may have answered my own question. It seems
std.typecon provides a facility for this.
http://dlang.org/phobos/std_typecons.html#.Proxy
http://dlang.org/phobos/std_typecons.html#.Typedef
Is this the 'right' way to do thi
On Saturday, 14 March 2015 at 16:55:09 UTC, Charles Cooper wrote:
Interesting. I think in the second example there are
pathological cases where one has similar declarations in two
modules at the same line.
Yes, that right, I've kept it simple, but of course it is not
complete safe. :)
Interesting. I think in the second example there are pathological
cases where one has similar declarations in two modules at the
same line.
moduleA.d:100
alias dollars_t TypeDef!int;
moduleB.d:100
alias cents_t TypeDef!int;
main.d:
import moduleA;
import moduleB;
void write_dollars_to_database
You can do it this way:
struct dollars_t {
uint _dollar;
this(uint d) {
_dollar = d;
}
alias _dollar this;
}
struct cents_t {
uint _cent;
this(uint c) {
_cent = c;
}
alias _cent this;
}
void do_something_with_dollars(dollars_t d) {
wri
I think I may have answered my own question. It seems std.typecon
provides a facility for this.
http://dlang.org/phobos/std_typecons.html#.Proxy
http://dlang.org/phobos/std_typecons.html#.Typedef
Is this the 'right' way to do things? It seems that Proxy is used
as a mixin whereas Typedef is use
I was wondering what the idiomatic D way of implementing strong
types. Boost has something along these lines using classes:
http://www.boost.org/doc/libs/1_37_0/boost/strong_typedef.hpp
When programming in C++ I find that the compiler does not
necessarily generate good code with these types, an