How to avoid inout type constructor with Optional type wrapper undoing string type

Timoses timosesu at gmail.com
Wed Jul 25 08:41:46 UTC 2018


On Tuesday, 24 July 2018 at 14:11:51 UTC, Ali Çehreli wrote:
> On 07/24/2018 02:47 AM, Timoses wrote:
>
> > Why does this fail while it works when replacing T with U in
> struct
> > W(T)?? It's so odd. Both T and U seem to resolve to "string".
> >
> >      struct W(T) {
> >          const T value;
> >          // Replacing `T value` with `U value` compiles
> >          this(U : T)(auto ref const T value) {
>
> That means, "any U that can implicitly be converted to string". 
> However, when U does not appear in the function parameter list, 
> there is no way for the compiler to deduce U. (I don't think 
> there is syntax to specify constructor template parameters 
> explicitly.)
>
> And if the parameter is always T, why is the constructor a 
> template? Ok, perhaps U is used inside the constructor and the 
> programmer needs to specify it... Still, I don't think there is 
> such syntax.
>
> Ali

Ah, thanks!


More information about the Digitalmars-d-learn mailing list