mn_scoped_ptr.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2018-2020 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef _MINLIB_c5301b07_8f99_414e_83fd_742896aab4d6_H_
20 #define _MINLIB_c5301b07_8f99_414e_83fd_742896aab4d6_H_
21 
22 #include "../mn_config.hpp"
23 
24 
25 #include "../mn_algorithm.hpp"
26 #include "../mn_def.hpp"
27 
28 namespace mn {
29  namespace pointer {
30 
31  template <typename T>
33  public:
34  using value_type = T;
35  using element_type = T;
36  using pointer = value_type*;
39 
40  explicit basic_scoped_ptr( pointer pValue = 0 ) : m_pPointer( pValue ) { }
42 
43  void swap(self_type& b) { mn::swap<value_type*>(m_pPointer, b.m_pPointer); }
44  void reset( pointer pValue = 0) { self_type(pValue).swap(*this); }
45 
46  pointer get() { return m_pPointer; }
47 
48  pointer operator -> () { assert(m_pPointer != 0); return m_pPointer; }
49  value_type& operator *() { assert(m_pPointer != 0); return *m_pPointer; }
50 
51  operator bool() { return m_pPointer != 0; }
52  private:
54  };
55 
61  template<typename T, typename... Args >
62  inline basic_scoped_ptr<T> make_scoped(Args&&... args) {
63  return basic_scoped_ptr<T>(new T (mn::forward<Args>(args)...) );
64  }
65 
66  template <typename T>
68 
69 
70  } // namespace pointer
71 } // namespace mn
72 
73 #endif
Definition: mn_scoped_ptr.hpp:32
basic_scoped_ptr(pointer pValue=0)
Definition: mn_scoped_ptr.hpp:40
const value_type const_value_type
Definition: mn_scoped_ptr.hpp:37
void swap(self_type &b)
Definition: mn_scoped_ptr.hpp:43
pointer operator->()
Definition: mn_scoped_ptr.hpp:48
basic_scoped_ptr< value_type > self_type
Definition: mn_scoped_ptr.hpp:38
T value_type
Definition: mn_scoped_ptr.hpp:34
void reset(pointer pValue=0)
Definition: mn_scoped_ptr.hpp:44
pointer m_pPointer
Definition: mn_scoped_ptr.hpp:53
value_type * pointer
Definition: mn_scoped_ptr.hpp:36
~basic_scoped_ptr()
Definition: mn_scoped_ptr.hpp:41
pointer get()
Definition: mn_scoped_ptr.hpp:46
value_type & operator*()
Definition: mn_scoped_ptr.hpp:49
T element_type
Definition: mn_scoped_ptr.hpp:35
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
basic_scoped_ptr< T > make_scoped(Args &&... args)
Make a scoped pointer.
Definition: mn_scoped_ptr.hpp:62
Definition: mn_allocator_typetraits.hpp:25