LIBINT  2.6.0
smart_ptr.h
1 /*
2  * Copyright (C) 2004-2019 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  using namespace boost;
30 
31  // For now I'll do a cheat since templated typedefs are not standard
32  // Should probably at least derive SafePtr from shared_ptr
33  #define SafePtr boost::shared_ptr
34  #define EnableSafePtrFromThis boost::enable_shared_from_this
35  #define SafePtr_from_this shared_from_this
36 #else
37  #include <memory>
38  // For now I'll do a cheat since templated typedefs are not standard
39  // Should probably at least derive SafePtr from shared_ptr
40  #define SafePtr std::shared_ptr
41  #define EnableSafePtrFromThis std::enable_shared_from_this
42  #define SafePtr_from_this shared_from_this
43  using std::dynamic_pointer_cast;
44 #endif
45 
46 namespace libint2 {
47 namespace detail {
49 template <typename T>
50 struct IsSafePtr {
51  enum { result = false };
52 };
53 
54 template <typename T>
55 struct IsSafePtr< SafePtr<T> > {
56  enum { result = true };
57 };
58 template <typename T>
59 struct IsSafePtr< const SafePtr<T> > {
60  enum { result = true };
61 };
62 template <typename T>
63 struct IsSafePtr< SafePtr<T>& > {
64  enum { result = true };
65 };
66 template <typename T>
67 struct IsSafePtr< const SafePtr<T>& > {
68  enum { result = true };
69 };
70 } // namespace detail
71 } // namespace libint2
72 
73 #endif
74 
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:50