strusBase  0.17
unique_ptr.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
9 #ifndef _STRUS_BASE_UNIQUE_PTR_HPP_INCLUDED
10 #define _STRUS_BASE_UNIQUE_PTR_HPP_INCLUDED
11 
12 #if __cplusplus >= 201103L
13 #include <memory>
14 
15 namespace strus {
16 template <typename T>
17 class unique_ptr : public std::unique_ptr<T>
18 {
19 public:
20  explicit unique_ptr( T* p = 0 ) :std::unique_ptr<T>(p) {}
21 };
22 } //namespace
23 #else
24 #if BOOST_VERSION < 105800
25 #include <boost/interprocess/smart_ptr/unique_ptr.hpp>
26 #define BOOST_UNIQUE_PTR_TEMPLATE boost::movelib::unique_ptr
27 #else
28 #include <boost/move/unique_ptr.hpp>
29 #define BOOST_UNIQUE_PTR_TEMPLATE boost::unique_ptr
30 #endif
31 
32 namespace strus {
33 template <typename T>
35 {
36  void operator()(T* ptr) const {delete ptr;}
37  template <class U>
38  void operator()(U* ptr) const {delete[] ptr;}
39 };
40 
41 template <typename T>
43  :public BOOST_UNIQUE_PTR_TEMPLATE<T,DefaultDeleter<T> >
44 {
45 public:
46  explicit unique_ptr( T* p = 0 ) :BOOST_UNIQUE_PTR_TEMPLATE<T,DefaultDeleter<T> >(p) {}
47 };
48 } //namespace
49 #endif
50 #endif
51 
52 
Definition: unique_ptr.hpp:34
#define BOOST_UNIQUE_PTR_TEMPLATE
Definition of strus::unique_ptr as wrapper to std::unique_ptr or boost::unique_ptr depeding on availa...
Definition: unique_ptr.hpp:26
void operator()(U *ptr) const
Definition: unique_ptr.hpp:38
unique_ptr(T *p=0)
Definition: unique_ptr.hpp:46
void operator()(T *ptr) const
Definition: unique_ptr.hpp:36
Definition: unique_ptr.hpp:42