title: Wrapping a C++ class and accumulating return values for its member methods
body: <p>I have a serializer class that serializes data through sequenced method calls:</p>
  <pre><code>enum class Status {
      INVALID_KEY = -2,
      OUT_OF_SPACE = -1,
      SUCCESS = 0
  };
  
  bool IsError(Status s) {
      return s != Status::SUCCESS;
  }
  
  class Serializer {
  public:
      void Init();
      Status BeginStruct();
      Status EncodeKeyValue(int key, std::string value);
      Status EndStruct();
  };
  </code></pre>
  <p>When I sequence those methods, it makes for some cumbersome writing:</p>
  <pre><code>    f.Init();
  
      status = f.BeginStruct();
      if (IsError(status)) {
          return -1;
      }
  
      status = f.EncodeKeyValue(2, &quot;test-value&quot;);
      if (IsError(status)) {
          return -1;
      }
  
      status = f.EndStruct();
      if (IsError(status)) {
          return -1;
      }
  </code></pre>
  <p>How can I achieve something like the following:</p>
  <pre><code>    wrappedf.BeginStruct()
          .EncodeKeyValue(2, &quot;test-value&quot;)
      .EndStruct();
      
      if (IsError(wrappedf.GetAccumulatedStatus()) {
          return -1;
      }
  </code></pre>
  <p>Constraints: I would like to avoid modifying Serializer's declaration or definition if possible.</p>