Skip to content
Snippets Groups Projects
Commit 34221a8d authored by Oliver Sander's avatar Oliver Sander
Browse files

implement cast to bool and reset(T*)

[[Imported from SVN: r5746]]
parent 31d97b50
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,9 @@ namespace Dune
*/
inline void reset();
/** \brief Detach shared pointer and set it anew for the given pointer */
inline void reset(T* pointer);
/** \brief The number of shared_ptrs pointing to the object we point to */
int use_count() const;
......@@ -114,6 +117,19 @@ namespace Dune
/** @brief Destructor, deletes element_type* rep_. */
~PointerRep() { delete rep_; }
} *rep_;
// Needed for the implicit conversion to "bool"
private:
typedef T* shared_ptr::PointerRep::*__unspecified_bool_type;
public:
/** \brief Implicit conversion to "bool" */
operator __unspecified_bool_type() const // never throws
{
return rep_ == 0 ? 0 : &shared_ptr::PointerRep::rep_;
}
};
template<class T>
......@@ -191,6 +207,13 @@ namespace Dune
}
}
template<class T>
inline void shared_ptr<T>::reset(T* pointer)
{
reset();
rep_ = new PointerRep(pointer);
}
/** @} */
#endif // #ifdef SHARED_PTR_NAMESPACE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment