Immutable container with mutable content

后端 未结 4 1795
遇见更好的自我
遇见更好的自我 2021-01-04 15:49

The story begins with something I thought pretty simple :

I need to design a class that will use some STL containers. I need to give users of the class access to an

4条回答
  •  甜味超标
    2021-01-04 16:02

    The painful solution:

    /* YOU HAVE NOT SEEN THIS */
    struct mutable_int {
        mutable_int(int v = 0) : v(v) { }
        operator int(void) const { return v; }
        mutable_int const &operator=(int nv) const { v = nv; return *this; }
    
        mutable int v;
    };
    

    Excuse me while I have to punish myself to atone for my sins.

提交回复
热议问题