April 02

On Thursday, 1 April 2021 at 23:21:56 UTC, Ali Çehreli wrote:

>

As I mentioned elsewhere in this thread, the element type must not have indirections though. If S is a struct with indirections, concatenating const(S)[] should still produce const(S)[].

Thanks.

Got something working that allows the implicit conversion at

https://github.com/dlang/dmd/pull/12341

for the sample code

@safe pure unittest
{
    const(char)[] x;
    string y;
    string z1 = x ~ y; // now passes
    string z2 = y ~ x; // now passes
}

but nothing else.

Feel perfectly free to fill in the details or even take over the PR.

April 02
On 4/1/21 6:55 PM, H. S. Teoh wrote:
> On Thu, Apr 01, 2021 at 06:34:04PM -0400, Steven Schveighoffer via Digitalmars-d wrote:
> [...]
>> ```d
>> auto concat(T, U)(T[] x, U[] y) pure
>> {
>>      return x ~ y;
>> }
>>
>> void main()
>> {
>>      string x;
>>      const(char)[] y;
>>      string z = concat(x, y); // compiles
>> }
>> ```
> [...]
> 
> Put this way, the solution becomes obvious: `~` should be considered a
> pure operation.  Then the compiler (in theory) ought to be able to
> infer uniqueness from `x ~ y`, and consequently allow implicit
> conversion to immutable.

It is considered pure, note that I'm using concatenation inside the function (which is marked pure).

-Steve
Next ›   Last »
1 2 3