[Issue 7019] implicit constructors are inconsistently allowed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 26 13:55:58 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7019
mail.mantis.88 at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mail.mantis.88 at gmail.com
--- Comment #7 from mail.mantis.88 at gmail.com 2012-01-26 13:55:55 PST ---
(In reply to comment #0)
> Yes, I'm aware that alias this makes it possible to allow implicit conversions,
> but it can't solve everything, esp. if you need to modify the value before you
> 'save' it:
> ...
Why not aliasing this to set/get methods, e.g:
struct Foo(T) {
alias prop this;
this( in T value ) {
m_Prop = value;
}
@property:
T prop() const {
return m_Prop;
}
ref auto prop( in T value ) {
return(m_Prop = value, this);
}
private:
T m_Prop;
}
void bar(T)( in Foo!T foo ) {
writeln( cast(T)foo );
}
int main() {
Foo!int foo = 42;
bar( foo );
foo = 10;
bar( foo );
return 0;
}
Are there any problems I'm not aware of?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list