Thread overview | |||||
---|---|---|---|---|---|
|
June 01, 2020 Copy constructors and IsExpression | ||||
---|---|---|---|---|
| ||||
https://dlang.org/spec/expression.html#is_expression ...specifically, the second form, i.e. `is(Type : TypeSpecialization)`: "The condition is satisfied if Type is semantically correct and it is the same as or can be implicitly converted to TypeSpecialization". Copy constructors expand the realm of implicit conversions, yet the IsExpression doesn't seem to consider them: --- struct S { int* ptr; // note the pointer this(ref scope const S) { /* ... */ } } S copy(ref const S s) { return s; } // OK void takesMutable(S s) {} void givesConst() { const S s; takesMutable(s); // OK } static assert(is(const(S) : S)); // Asserts --- Was the implementation intentionally not amended to allow for copy constructors, or was this an oversight? It does, after all, accept conversions provided by the `alias this`, so why not copy ctors? There are a few areas of the language and libraries, including druntime, that are ignoring copy constructors (for example, arrays). Is this also one of those? On another note, is there really no way of recovering password here? I keep forgetting it on a regular basis. |
June 01, 2020 Re: Copy constructors and IsExpression | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stanislav Blinov | On Monday, 1 June 2020 at 15:48:21 UTC, Stanislav Blinov wrote:
> There are a few areas of the language and libraries, including druntime, that are ignoring copy constructors (for example, arrays). Is this also one of those?
Very likely, as in not adapted after the addition of copy ctors.
|
June 02, 2020 Re: Copy constructors and IsExpression | ||||
---|---|---|---|---|
| ||||
Posted in reply to kinke | On Monday, 1 June 2020 at 19:40:05 UTC, kinke wrote:
> On Monday, 1 June 2020 at 15:48:21 UTC, Stanislav Blinov wrote:
>> There are a few areas of the language and libraries, including druntime, that are ignoring copy constructors (for example, arrays). Is this also one of those?
>
> Very likely, as in not adapted after the addition of copy ctors.
Hm, having slept on it, I think, if `is(A:B)` did the check, this could blow up as a chicken-or-egg:
```
struct S {
this(T)(ref scope T) if (!is(T : S)) { /* ... */ }
}
```
|
Copyright © 1999-2021 by the D Language Foundation