March 05, 2007 Re: Classes in D and C++ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uno | Uno wrote:
>> You can do:
>>
>> auto x = X(3);
>>
>> and x will be put on the stack.
>
> I didn't know that shortcut.. thanks! Now it looks much better and it's acceptable for me, but c++ form is still shorter and more elegant (of course it's disputable).
The problem with the C++ form is that it's semantically identical to a function prototype statement. I do think it would be great if there were a common syntax to construct all types in D, but I'm not sure if "X x(a)" is it. "X x = X(a)" is probably better. But I'd like this to work for concrete types as well.
Sean
|
March 05, 2007 Re: Classes in D and C++ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Lionello Lunesu wrote:
>
> Actually, I was surprised myself, but it did work. And come to think of it, I remember Walter mentioning that he made it work, but I can't seem to find any reference to this in the changelog...
I must have missed the comment. Glad to hear it!
Sean
|
March 05, 2007 Re: Classes in D and C++ | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Little | Andy Little wrote: > Lionello Lunesu Wrote: > > >>SomeType st = 2;//construction >> >>No need for constructors ;) > > > OK, To explain why I don't want to allow this syntax I need to explain som of how the quan library works. > > Its main purpose is to catch errors in dimensional analysis. > Take a look at this lib. It does most of what I see your lib doing and might give you some ides on how to make yours work in D. http://www.csc.kth.se/~ol/physical.d |
March 05, 2007 Re: Classes in D and C++ | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS Wrote:
> Andy Little wrote:
> > Lionello Lunesu Wrote:
> >
> >
> >>SomeType st = 2;//construction
> >>
> >>No need for constructors ;)
> >
> >
> > OK, To explain why I don't want to allow this syntax I need to explain som of how the quan library works.
> >
> > Its main purpose is to catch errors in dimensional analysis.
> >
>
> Take a look at this lib. It does most of what I see your lib doing and might give you some ides on how to make yours work in D.
>
> http://www.csc.kth.se/~ol/physical.d
Hey, that looks interesting, certainly a lot leaner than my Quan library. The example made me laugh as it seems to be a D version of one of the examples in Quan. It will be interesting to study as I know the domain and so it will certainly help me to understand a bit more about D.
Are there any plans to flesh it out? ( though it looks pretty functional already). Seems like it could be a nice example for D.
regards
Andy Little
|
Copyright © 1999-2021 by the D Language Foundation