Skip to content
  • Mark OLESEN's avatar
    ENH: add get() retrieval of a pointer from PtrLists, HashPtrTable · fa71840d
    Mark OLESEN authored
    - naming similarity with autoPtr, unique_ptr and other containers.
    
      For UPtrList derivatives, this is equivalent to the existing
      operator(). The read-only variant is also equivalent to the
      single-parameter 'set(label)' method.
    
      With PtrList<T> list(...) :
    
          const T* ptr = list.get(10);
          if (ptr)
          {
              ptr->method();
          }
    
      vs.
          if (list.set(10))
          {
              list[10].method();
          }
    
      For HashPtrTable there is only a read-only variant which is equivalent
      to testing for existence and for value.
    
      With HashPtrTable<T> hash(...) :
    
          const T* ptr = list.get("key");
          if (ptr)
          {
              ptr->method();
          }
    
      vs.
          if (list.found("key"))
          {
              // Fails on null pointer!!
              list["key"].method();
          }
    
    Use of get() is largely a matter of taste or local coding requirements
    fa71840d