Hi,

I read that if a structure only contains a reference, it will behave like a reference type in function calls (needed for specifying reference behavior in a type tuple). I need exactly that behavior. I am currently unsure whether it is possible at all to have such a construct which works at user side exactly like a boolean (booleans can be assigned and directly compared with ==) but internally are pointers...

(The coding does not compile)

Kind regards
André


struct PrimitiveRef(T)
{
        private T* _value;

        alias  _value this;
        
        void opAssign(T v)
        {
                _value = v;
        }
        
}
alias BoolRef = PrimitiveRef!bool;

void test(BoolRef b)
{
        b = true;
}

void main()
{
        BoolRef b = false;
        test(b);
        assert(b == true);      
}

Reply via email to