Boost logo

Boost :

Subject: [boost] [type trait extension] I hate volatile...
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2011-07-15 19:22:49


I am still working on the implementation of the traits to detect operators.
I have an issue with operators returning a volatile object (being a
reference or not). This breaks the code I wrote to detect if the
return type is void or not.
In particular, the following code compiles with RET=int but not with
RET=ret. Can somebody tell me why?

It seems that any volatile object (reference or not) cannot be bound
to a const reference apart for fundamental types. So is there any
useful case to return a volatile object?
If not, I can maybe just ignore those cases or it becomes to be a
nightmare. By the way, it is 1:30am. I am going to bed!

Frédéric

struct ret { };

#define RET int

RET result;

RET r() { return result; }
RET const rc() { return result; }
RET volatile rv() { return result; } // fails to compile
RET const volatile rcv() { return result; } // fails to compile
RET & rr() { return result; }
RET const & rcr() { return result; }
RET volatile & rvr() { return result; } // fails to compile
RET const volatile & rcvr() { return result; } // fails to compile

int main() {
        RET x;
        x=r();
        x=rc();
        x=rv(); // fails with RET=ret
        x=rcv(); // fails with RET=ret
        x=rr();
        x=rcr();
        x=rvr();
        x=rcvr();
        return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk