On 3/27/22 22:32, vit wrote:
> int* getX(T)(return auto ref T t)
> if(is(T == class) || (is(T == struct) && __traits(isRef, t))){
> return &t.x;
> }
I also think 'return' parameter is needed but I could not come up with
an example where that 'return' provides any more safety. Compiler
alr
On 3/27/22 09:27, JN wrote:
> I would like to have only one definition of getX if possible, because
> they both are doing the same thing. I can't remove the ref one, because
> without a ref it will pass the struct as a temporary and compiler won't
> like that.
Combining all responses, the code at
On Sunday, 27 March 2022 at 16:27:44 UTC, JN wrote:
I would like to have only one definition of getX if possible,
because they both are doing the same thing. I can't remove the
ref one, because without a ref it will pass the struct as a
temporary and compiler won't like that.
```d
import std.
On 3/27/22 12:27 PM, JN wrote:
int* getX(T)(T t)
{
return &t.x;
}
Remove this one. It's a bad idea. It probably won't compile, but if it
does, you will be using corrupted memory.
-Steve
Auto ref?
```D
int* getX(T)(auto ref T t)
{
...
```
I would like to have only one definition of getX if possible,
because they both are doing the same thing. I can't remove the
ref one, because without a ref it will pass the struct as a
temporary and compiler won't like that.
```d
import std.stdio;
struct Foo
{
int x;
void doStuff()