• Mark Olesen's avatar
    ENH: support writable reference for tmp (#1775) · be058bec
    Mark Olesen authored
    - improves flexibility. Can tag a tmp as allowing non-const access to
      the reference and skip additional const_cast in following code. For
      example,
    
          tmp<volScalarField> tfld(nullptr);
          auto* ptr = getObjectPtr<volScalarField>("field");
          if (ptr)
          {
              tfld.ref(*ptr);
          }
          else
          {
              tfld.reset(volScalarField::New(...));
          }
          auto& fld = tfld.ref();
    
    ENH: renamed tmpNrc to refPtr
    
    - the name 'refPtr' (reference|pointer) should be easier to remember
      than tmpNrc (tmp, but non-ref-counted).
    
    - provide tmpNrc typedef and header for code compatibility
    
    NOTE
    
    - in some places refPtr and tmp can be used instead of a
      std::reference_wrapper for handling external references.
    
      Unlike std::reference_wrapper, it can be default constructed
      (holding nothing), whereas reference_wrapper may need a dummy
      reference. However, the lifetime extension of references _may_ be
      better with reference_wrapper.
    be058bec
tmpI.H 9.45 KB