Implicit conversion of concatenation result to immutable
    Steven Schveighoffer 
    schveiguy at gmail.com
       
    Fri Apr  2 13:25:57 UTC 2021
    
    
  
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
    
    
More information about the Digitalmars-d
mailing list