digitalmars.D - Generic assumeUnique
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (8/8) May 05 2022 Why isn't `std.exception.assumeUnique` generically defined as
- Dennis (7/17) May 05 2022 The documentation says:
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (7/9) May 05 2022 http://mir-algorithm.libmir.org/mir_string_map.html
Why isn't `std.exception.assumeUnique` generically defined as ```d auto assumeUnique(T)(T x) trusted { return cast(immutable)x; } ``` instead of currently restricted to arrays at https://github.com/dlang/phobos/blob/master/std/exception.d#L905?
May 05 2022
On Thursday, 5 May 2022 at 08:15:35 UTC, Per Nordlöw wrote:Why isn't `std.exception.assumeUnique` generically defined as ```d auto assumeUnique(T)(T x) trusted { return cast(immutable)x; } ```That's not a correct use of ` trusted`instead of currently restricted to arrays at https://github.com/dlang/phobos/blob/master/std/exception.d#L905?The documentation says:Typically, `assumeUnique` is used to return arrays from functions that have allocated and built them.For a `struct` or `class`, you would typically use an `immutable` / `pure` constructor, so there's less need for it. What non-array type do you want to use `assumeUnique` on and why don't you `cast(immutable)`?
May 05 2022
On Thursday, 5 May 2022 at 12:32:07 UTC, Dennis wrote:What non-array type do you want to use `assumeUnique` on and why don't you `cast(immutable)`?http://mir-algorithm.libmir.org/mir_string_map.html I _can_ use `cast(immutable)` but that needs to be qualified as trusted. `StringMap` is implemented using three pointers fields and one length field and is a hybrid between a normal array and an associative array.
May 05 2022