aboutsummaryrefslogtreecommitdiff
path: root/libbutl/const-ptr.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-09-22 23:32:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-09-22 23:32:28 +0200
commitc09cd7512491cee1e82c1ad8128ce9fd4bc3f79b (patch)
treea659ed768d849130ab5780a11b7f791a463a1a91 /libbutl/const-ptr.hxx
parent2a00871f07067f8f9e2de08bb9c8f50e1bf6a650 (diff)
Initial modularization with both Clang and VC hacks
Note: gave up on VC about half way though.
Diffstat (limited to 'libbutl/const-ptr.hxx')
-rw-r--r--libbutl/const-ptr.hxx80
1 files changed, 0 insertions, 80 deletions
diff --git a/libbutl/const-ptr.hxx b/libbutl/const-ptr.hxx
deleted file mode 100644
index e50704d..0000000
--- a/libbutl/const-ptr.hxx
+++ /dev/null
@@ -1,80 +0,0 @@
-// file : libbutl/const-ptr.hxx -*- C++ -*-
-// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
-// license : MIT; see accompanying LICENSE file
-
-#ifndef LIBBUTL_CONST_PTR_HXX
-#define LIBBUTL_CONST_PTR_HXX
-
-#include <cstddef> // nullptr_t
-
-namespace butl
-{
- // Const-propagating pointer.
- //
- // It has the semantics of a raw pointer except that it passes on its own
- // const-ness to the pointed-to object. In other words, if you have a const
- // instance of this pointer, then you can only obtain a const raw pointer to
- // the underlying object. It is normally used as a data member, for example:
- //
- // struct tree
- // {
- // const_ptr<tree> left;
- // const_ptr<tree> right;
- //
- // void modify ();
- // };
- //
- // tree* x = ...;
- // const tree* y = ...;
- //
- // x.left->modify (); // Ok.
- // y.left->modify (); // Error.
- //
- // Note that due to this semantics, copy construction/assignment requires
- // a non-const instance of const_ptr.
- //
- // Note that this type is standard layout (which means we can reinterpret
- // it as a raw pointer).
- //
- // Known drawbacks/issues:
- //
- // 1. Cannot do static_cast<mytree*> (x.left).
- //
- template <typename T>
- class const_ptr
- {
- public:
- const_ptr () = default;
- explicit const_ptr (T* p): p_ (p) {}
- const_ptr (std::nullptr_t): p_ (nullptr) {}
-
- const_ptr& operator= (T* p) {p_ = p; return *this;}
- const_ptr& operator= (std::nullptr_t) {p_ = nullptr; return *this;}
-
- template <class T1> explicit const_ptr (T1* p): p_ (p) {}
- template <class T1> const_ptr (const_ptr<T1>& p): p_ (p.p_) {}
-
- template <class T1> const_ptr& operator= (T1* p) {p_ = p; return *this;}
- template <class T1> const_ptr& operator= (const_ptr<T1>& p) {
- p_ = p.p_; return *this;}
-
- T* operator-> () {return p_;}
- const T* operator-> () const {return p_;}
-
- T& operator* () {return *p_;}
- const T& operator* () const {return *p_;}
-
- operator T* () {return p_;}
- operator const T* () const {return p_;}
-
- explicit operator bool () const {return p_ != nullptr;}
-
- T* get () {return p_;}
- const T* get () const {return p_;}
-
- private:
- T* p_;
- };
-}
-
-#endif // LIBBUTL_CONST_PTR_HXX