On 2019-10-30 00:28, Simen Kjærås wrote:

Something like this?

T readOnce(T)(ref T value) {
     auto tmp = value;
     value = T.init;
     return tmp;
} unittest {
     int i = 3;
     assert(i.readOnce == 3);
     assert(i == 0);
}

Perhaps better to encapsulate it in a struct to avoid someone accessing the value directly.

--
/Jacob Carlborg

Reply via email to