Developer documentation
Version 3.0.3-105-gd3941f44
memory.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __memory_h__
18#define __memory_h__
19
20#include <memory>
21
22#define NOMEMALIGN
23
27namespace MR
28{
29
30 template<class T, class Deleter = std::default_delete<T>>
31 class copy_ptr : public std::unique_ptr<T, Deleter>
33 public:
34 constexpr copy_ptr () noexcept : std::unique_ptr<T,Deleter>() { }
35 constexpr copy_ptr (std::nullptr_t) noexcept : std::unique_ptr<T,Deleter>() { }
36 explicit copy_ptr (T* p) noexcept : std::unique_ptr<T,Deleter> (p) { }
37 copy_ptr (const copy_ptr& u) : std::unique_ptr<T,Deleter>(u ? new T (*u) : nullptr) { }
38 copy_ptr (copy_ptr&& u) noexcept : std::unique_ptr<T,Deleter>(std::move(u)) { }
39 template< class U, class E >
40 copy_ptr (copy_ptr<U, E>&& u) noexcept : std::unique_ptr<T,Deleter>(std::move(u)) { }
41
42 copy_ptr& operator=(const copy_ptr& u) { this->reset (u ? new T (*u) : nullptr); return *this; }
43 };
44
46 template <class X>
47 bool operator() (const X& a, const X& b) const { return *a < *b; }
48 template <class X>
49 bool operator() (const std::shared_ptr<X>& a, const std::shared_ptr<X>& b) const { return *a < *b; }
50 };
51
52}
53
54#endif
55
copy_ptr(copy_ptr< U, E > &&u) noexcept
Definition: memory.h:40
copy_ptr(T *p) noexcept
Definition: memory.h:36
copy_ptr(const copy_ptr &u)
Definition: memory.h:37
constexpr copy_ptr() noexcept
Definition: memory.h:34
copy_ptr & operator=(const copy_ptr &u)
Definition: memory.h:42
constexpr copy_ptr(std::nullptr_t) noexcept
Definition: memory.h:35
copy_ptr(copy_ptr &&u) noexcept
Definition: memory.h:38
#define NOMEMALIGN
Definition: memory.h:22
Definition: base.h:24
Definition: types.h:303
bool operator()(const X &a, const X &b) const
Definition: memory.h:47