C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
SmartPtr.h
Go to the documentation of this file.
1 // Copyright András Vukics 2006–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
3 // -*- C++ -*-
4 #ifndef CPPQEDCORE_UTILS_SMARTPTR_H_INCLUDED
5 #define CPPQEDCORE_UTILS_SMARTPTR_H_INCLUDED
6 
7 #include <boost/shared_ptr.hpp>
8 
9 
10 namespace cpputils {
11 
12 
13 namespace details {
14 
15 template<typename T>
16 inline void nullDelete (T*) {}
17 
18 } // details
19 
20 
22 
31 template<typename T>
32 const boost::shared_ptr<T>
34  )
35 {
36  return boost::shared_ptr<T>(t,details::nullDelete<T>);
37 }
38 
39 
41 template<typename T>
42 const boost::shared_ptr<const T>
44  )
45 {
46  return boost::shared_ptr<const T>(t,details::nullDelete<T>);
47 }
48 
49 
51 template<typename T>
52 const boost::shared_ptr<T> sharedPointerize(boost::shared_ptr<T> t) {return t ;}
53 
55 template<typename T>
56 const boost::shared_ptr<T> sharedPointerize( T& t) {return nonOwningSharedPtr(&t);}
57 
59 template<typename T>
60 const boost::shared_ptr<T> sharedPointerize( T* t) {return nonOwningSharedPtr( t);}
61 
62 
63 } // cpputils
64 
65 
66 #endif // CPPQEDCORE_UTILS_SMARTPTR_H_INCLUDED
const boost::shared_ptr< const T > nonOwningConstSharedPtr(T *t)
Returns a “non-owning” shared pointer to const that doesn’t do anything on deletion.
Definition: SmartPtr.h:43
const boost::shared_ptr< T > nonOwningSharedPtr(T *t)
Returns a “non-owning” shared pointer that doesn’t do anything on deletion.
Definition: SmartPtr.h:33
Namespace comprising otherwise hard-to-classify generic utilities.
Definition: Algorithm.h:10
const boost::shared_ptr< T > sharedPointerize(boost::shared_ptr< T > t)
Part of a bundle of functions providing a unified interface to wrap objects into the shared-pointer i...
Definition: SmartPtr.h:52