Implicit conversion of concatenation result to immutable
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Apr 1 22:55:51 UTC 2021
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.
T
--
Never criticize a man until you've walked a mile in his shoes. Then when you do criticize him, you'll be a mile away and he won't have his shoes.
More information about the Digitalmars-d
mailing list