Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

7.16 SmartPtr Quick Facts

  • SmartPtr declaration:

    template
    <
      typename T,
      template <class> class OwnershipPolicy = RefCounted,
      class ConversionPolicy = DisallowConversion,
      template <class> class CheckingPolicy = AssertCheck,
      template <class> class StoragePolicy = DefaultSPStorage
    >
    class SmartPtr;
  • T is the type to which SmartPtr points. T can be a primitive type or a user-defined type. The void type is allowed.

  • For the remaining class template parameters (OwnershipPolicy, ConversionPolicy, CheckingPolicy, and StoragePolicy), you can implement your own policies or choose from the defaults mentioned in Sections 7.14.1 through 7.14.4.

  • OwnershipPolicy controls the ownership management strategy. You can select from the predefined classes DeepCopy, RefCounted, RefCountedMT, COMRefCounted, RefLinked, DestructiveCopy, and NoCopy, described in Section 7.14.2.

  • ConversionPolicy controls whether implicit conversion to the pointee type is allowed. The default is to forbid implicit conversion. Either way, you can still access the pointee object by calling GetImpl. You can use the AllowConversion and Disallow-Conversion implementations (Section 7.14.3).

  • CheckingPolicy defines the error checking strategy. The defaults provided are Assert-Check, AssertCheckStrict, RejectNullStatic, RejectNull, RejectNullStrict, and NoCheck (Section 7.14.4).

  • StoragePolicy defines the details of how the pointee object is stored and accessed. The default is DefaultSPStorage, which, when instantiated with a type T, defines the reference type as T&, the stored type as T*, and the type returned from operator-> as T* again. Other storage types defined by Loki are ArrayStorage, LockedStorage, and HeapStorage (Section 7.14.1).

  • + Share This
  • 🔖 Save To Your Account