4

I'm trying to pass a Document as a parameter (in this case to a C++ Class C'tor, but doens't really matter), and move it, so the orig Document will become Null, and the class member will hold the document.

Example:

class A
{
    rapidjson::Document m_payload;

    A(rapidjson::Document& payload)
    {
        m_payload = payload; // DOESN'T WORK ('operator =' is a private member of 'rapidjson::GenericDocument<...>')
    }
};

I know that if it would have been a Value, the operator= would have worked, but can't get it to work with Document.

Workarounds I found so far:

  1. m_payload.Swap(payload); // This works specifically here, but not what I wanted.

  2. m_payload = std::move(payload); // I prefer not to use C++11 operations.

Obviously I prefer to move and not copy considering performance.

brkeyal
  • 1,317
  • 1
  • 16
  • 22
  • 1
    moving is a C++11-only concept, so it doesn't really make sense to say that you "prefer not to use C++11 operations" – SJL May 11 '17 at 16:12
  • 1
    Rapidjson works by "Move Semantics" when doing value assignments, it's really not related to C++11. What I'm trying to do is to apply those move semantics when working with Document also. – brkeyal May 14 '17 at 08:23

0 Answers0