LIBINT 2.7.2
smart_ptr.h
1/*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_smartptr_h_
22#define _libint2_src_bin_libint_smartptr_h_
23
24#include <libint2/config.h>
25
26#if HAVE_SHARED_PTR_IN_BOOST
27 #include <boost/shared_ptr.hpp>
28 #include <boost/enable_shared_from_this.hpp>
29
30 // For now I'll do a cheat since templated typedefs are not standard
31 // Should probably at least derive SafePtr from shared_ptr
32 #define SafePtr boost::shared_ptr
33 #define EnableSafePtrFromThis boost::enable_shared_from_this
34 #define SafePtr_from_this shared_from_this
35 using boost::const_pointer_cast;
36 using boost::dynamic_pointer_cast;
37 using boost::static_pointer_cast;
38#else
39 #include <memory>
40 // For now I'll do a cheat since templated typedefs are not standard
41 // Should probably at least derive SafePtr from shared_ptr
42 #define SafePtr std::shared_ptr
43 #define EnableSafePtrFromThis std::enable_shared_from_this
44 #define SafePtr_from_this shared_from_this
45 using std::const_pointer_cast;
46 using std::dynamic_pointer_cast;
47 using std::static_pointer_cast;
48#endif
49
50namespace libint2 {
51namespace detail {
53template <typename T>
54struct IsSafePtr {
55 enum { result = false };
56};
57
58template <typename T>
59struct IsSafePtr< SafePtr<T> > {
60 enum { result = true };
61};
62template <typename T>
63struct IsSafePtr< const SafePtr<T> > {
64 enum { result = true };
65};
66template <typename T>
67struct IsSafePtr< SafePtr<T>& > {
68 enum { result = true };
69};
70template <typename T>
71struct IsSafePtr< const SafePtr<T>& > {
72 enum { result = true };
73};
74} // namespace detail
75} // namespace libint2
76
77#endif
78
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
Can be used to determine whether a type is a SafePtr.
Definition: smart_ptr.h:54