1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

mutable function argument

Discussion in 'C++' started by monarch_dodra, Sep 6, 2010.

  1. monarch_dodra

    monarch_dodra New Member

    Joined:
    Sep 6, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I have a function "foo". This function takes an argument arg. foo promises not to modify arg in a visible way. In reality, foo will do all kinds of non-const operation on arg, but by the end of it all, foo will be back to normal:

    Code:
    foo(const T& arg)
    {
    arg+=2; //modify foo
    ...do stuff
    arg-=2; //foo is back to normal
    }
    An arg object is actually pretty big, so I'd like to avoid copying them unless arg is an actual const (and not just const qualified). Is there a solution to this?
     

Share This Page