Operator Overloading and boilerplate code

Loopback elliott.darfink at gmail.com
Tue Jul 5 10:52:08 PDT 2011


On 2011-07-05 18:05, Ali Çehreli wrote:
> I don't want to look like brushing off the problem but having many
> constructors make the code complicated. For example, it may be confusing
> which constructor gets called here:
>
>      auto d = DVECTOR2(1.5);
>
That might be true. I just did what felt most convenient, but perhaps
that is not always the solution.

> D2 has changed the meaning of inout to mean something like "templatize
> just the mutable/const/immutable qualification of the parameter" but it
> is not implemented fully yet. Look at "Inout Functions" on the Functions
> spec:

Foolish of me to forget about inout functions. Is there any possibility
though that the inout tag offers a solution to my initial problem,
where the constructor couldn't be evaluted at compile time?

It feels a bit redundant if you would have to have unique constructors
just to enable support for immutable instantiations of your class, or
perhaps this lies within the use of templates and their generic
parameters?

I've been at this problem for over a day and it feels awful to be left
with no choice and move away from using templates and instead having
walls of boilerplate code just to support immutable and const
instantiations of one's structure.


More information about the Digitalmars-d-learn mailing list