aboutsummaryrefslogtreecommitdiff
path: root/libbutl/const-ptr.mxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-09-28 19:24:31 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-09-28 20:29:59 +0300
commitdf1ef68cd8e8582724ce1192bfc202e0b9aeaf0c (patch)
treeb731ca4c68e60c00c7e7d499dbf4868ee7b71f44 /libbutl/const-ptr.mxx
parent7a4fc37f264cdb67f2f83fa92703c869215bbc86 (diff)
Get rid of C++ modules related code and rename *.mxx files to *.hxx
Diffstat (limited to 'libbutl/const-ptr.mxx')
-rw-r--r--libbutl/const-ptr.mxx93
1 files changed, 0 insertions, 93 deletions
diff --git a/libbutl/const-ptr.mxx b/libbutl/const-ptr.mxx
deleted file mode 100644
index 343ecf6..0000000
--- a/libbutl/const-ptr.mxx
+++ /dev/null
@@ -1,93 +0,0 @@
-// file : libbutl/const-ptr.mxx -*- C++ -*-
-// license : MIT; see accompanying LICENSE file
-
-#ifndef __cpp_modules_ts
-#pragma once
-#endif
-
-// C includes.
-
-#ifndef __cpp_lib_modules_ts
-#include <cstddef> // nullptr_t
-#endif
-
-// Other includes.
-
-#ifdef __cpp_modules_ts
-export module butl.const_ptr;
-#ifdef __cpp_lib_modules_ts
-import std.core; // @@ MOD std.fundamental.
-#endif
-#endif
-
-#include <libbutl/export.hxx>
-
-LIBBUTL_MODEXPORT 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_;
- };
-}