Tech Off Post

Single Post Permalink

View Thread: C++0x (vs2010) question, please tell me what i'm doing wrong
  • User profile image
    Mr Crash

    , Dexter wrote

    Well, it seems to me that the only purpose of m_onLeaveScope_empty is to support the move constructor. You could leave the old m_onLeaveScope alone and add a null check in the scoped destructor so the old m_onLeaveScope doesn't get called.

    Yes, I've thought of that, it would work for the pointer version, but not for the non pointer version.

    We can't really test for m_obj != 0 since 0 might be a totally valid value.


    The possible solution would be to add a bool that gets set to true (is_empty = true) when the data is moved.

    This, i'm guessing, would also be faster then calling an empty function.


    But i'm not sure which way to go. I want it to be correct and as performance as possible so i'm still wondering if there is some kind of  template magic to sole this.


    But i'm leaning to the bool solution or perhaps i should use std::function...

    Am i overthinking it ?