Lumiera  0.pre.03
»edit your freedom«
p.hpp File Reference

Go to the source code of this file.

Description

Customised refcounting smart pointer.

Template derived from std::shared_ptr adding total ordering and type relationships implemented by forwarding to the pointees. In all other respects, it should behave exactly as shared_ptr and is able to cooperate and share ownership with other shared_ptr instantiations.

By default different instantiations of shared_ptr are completely unrelated types, even if using inheritance related type parameters for instantiation: a shared_ptr<Media> isn't some kind-of shared_ptr<Asset> – we need to do an explicit static_ptr_cast. Another common problem is the definition of equality and ordering relations for shared_ptr: equality is based on the equality of the managed pointers, while ordering is built upon the ref count. While generally this may be a good compromise, in our case it hinders treating the smart ptrs within the application almost as if they were the objects themselves and proved an obstacle for writing generic helper functions.

the P template resolves these problems by implementing the ordering operators in terms of the corresponding operators on the pointee and by allowing to specify a base class smart-ptr as template parameter.

See also
asset.hpp
custom-shared-ptr-test.cpp
orderingofassetstest.cpp

Definition in file p.hpp.

#include "lib/error.hpp"
#include "lib/meta/util.hpp"
#include <memory>

Classes

class  P< TAR, BASE >
 Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relationships and ordering operators to the pointee objects. More...
 

Functions

template<typename X , typename... ARGS>
P< X > makeP (ARGS &&... ctorArgs)
 Helper to create and manage by lib::P. More...
 

Namespaces

 lib
 Implementation namespace for support and library code.