Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: always use std::shared_ptr #276

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1361,51 +1361,6 @@ AC_COMPILE_IFELSE(
]
)

dnl ------------------ Check for shared_ptr -----------------------

HAVE_SHARED_PTR=no
AC_MSG_CHECKING([for std::shared_ptr])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <memory>
]],
[[
std::shared_ptr<int> a(new int);
std::shared_ptr<int> b = a;
]]
)
],
[AC_MSG_RESULT([yes])
HAVE_SHARED_PTR=std
],
[
AC_MSG_RESULT([no])
]
)

if test "X$HAVE_SHARED_PTR" = "Xno"; then
AC_MSG_CHECKING([for Boost::shared_ptr])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <boost/shared_ptr.hpp>
]],
[[
boost::shared_ptr<int> a(new int);
boost::shared_ptr<int> b = a;
]]
)
],
[AC_MSG_RESULT([yes])
HAVE_SHARED_PTR=boost
AC_DEFINE(HAVE_SHARED_PTR_IN_BOOST)
],
[
AC_MSG_RESULT([no])
AC_MSG_ERROR([shared_ptr is required. Please download Boost from boost.org or use C++ compiler that supports std::shared_ptr.])
]
)
fi

dnl ------------------ Check for Eigen library -----------------------

ACX_CHECK_EIGEN
Expand Down
3 changes: 0 additions & 3 deletions include/libint2/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@
/* C++ compiler allows template with default params as template template parameter */
#undef CXX_ALLOWS_DEFPARAMTEMPLATE_AS_TEMPTEMPPARAM

/* is shared_ptr in boost? */
#undef HAVE_SHARED_PTR_IN_BOOST

/* define if Eigen library is available. */
#undef LIBINT_HAS_EIGEN

Expand Down
2 changes: 1 addition & 1 deletion src/bin/libint/algebra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace libint2 {

template <>
void
AlgebraicOperator<DGVertex>::add_exit_arc(const SafePtr<DGArc>& a)
AlgebraicOperator<DGVertex>::add_exit_arc(const std::shared_ptr<DGArc>& a)
{
DGVertex::add_exit_arc(a);
#if CHECK_SAFETY
Expand Down
34 changes: 17 additions & 17 deletions src/bin/libint/algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ namespace libint2 {
typedef algebra::OperatorTypes::OperatorType OperatorType;

AlgebraicOperator(OperatorType OT,
const SafePtr<T>& left,
const SafePtr<T>& right) :
const std::shared_ptr<T>& left,
const std::shared_ptr<T>& right) :
DGVertex(ClassInfo<AlgebraicOperator>::Instance().id()), OT_(OT), left_(left), right_(right),
label_(algebra::OperatorSymbol[OT_])
{
}
virtual ~AlgebraicOperator() {}

/// Clone A but replace operands with left and right
AlgebraicOperator(const SafePtr<AlgebraicOperator>& A,
const SafePtr<T>& left,
const SafePtr<T>& right) :
AlgebraicOperator(const std::shared_ptr<AlgebraicOperator>& A,
const std::shared_ptr<T>& left,
const std::shared_ptr<T>& right) :
DGVertex(static_cast<DGVertex&>(*A)), OT_(A->OT_),
left_(left), right_(right), label_(A->label_)
{
Expand All @@ -90,38 +90,38 @@ namespace libint2 {
/// Returns the OperatorType
OperatorType type() const { return OT_; }
/// Returns the left argument
const SafePtr<T>& left() const { return left_; }
const std::shared_ptr<T>& left() const { return left_; }
/// Returns the right argument
const SafePtr<T>& right() const { return right_; }
const std::shared_ptr<T>& right() const { return right_; }

/// Overloads DGVertex::add_exit_arc(). The default definition is used unless T = DGVertex (see algebra.cc)
void add_exit_arc(const SafePtr<DGArc>& a) override;
void add_exit_arc(const std::shared_ptr<DGArc>& a) override;
/// Implements DGVertex::size()
unsigned int size() const override { return 1; }
/// Implements DGVertex::equiv()
bool equiv(const SafePtr<DGVertex>& a) const override
bool equiv(const std::shared_ptr<DGVertex>& a) const override
{
if (typeid_ == a->typeid_) {
#if ALGEBRAICOPERATOR_USE_KEY_TO_COMPARE
#if USE_INT_KEY_TO_COMPARE
if (key() == a->key())
return *this == static_pointer_cast<AlgebraicOperator,DGVertex>(a);
return *this == std::static_pointer_cast<AlgebraicOperator,DGVertex>(a);
else
return false;
#else
return description() == a->description();
#endif
#else
return *this == static_pointer_cast<AlgebraicOperator,DGVertex>(a);
return *this == std::static_pointer_cast<AlgebraicOperator,DGVertex>(a);
#endif
}
else
return false;
}

/// laboriously compare 2 operators element by element
bool operator==(const SafePtr<AlgebraicOperator>& a) const {
#if ALGEBRAICOPERATOR_USE_SAFEPTR
bool operator==(const std::shared_ptr<AlgebraicOperator>& a) const {
#if ALGEBRAICOPERATOR_USE_SHAREDPTR
// Find out why sometimes equivalent left_ and a->left_ have non-equivalent pointers
if (left_->equiv(a->left()) && left_ != a->left_) {
std::cout << "Left arguments are equivalent but pointers differ!" << std::endl;
Expand All @@ -136,7 +136,7 @@ namespace libint2 {
}
#endif
if (OT_ == a->OT_) {
#if ALGEBRAICOPERATOR_USE_SAFEPTR
#if ALGEBRAICOPERATOR_USE_SHAREDPTR
if (left_ == a->left_ && right_ == a->right_)
#else
if (left_->equiv(a->left()) && right_->equiv(a->right()))
Expand Down Expand Up @@ -189,8 +189,8 @@ namespace libint2 {

private:
OperatorType OT_;
SafePtr<T> left_;
SafePtr<T> right_;
std::shared_ptr<T> left_;
std::shared_ptr<T> right_;

/// Implements DGVertex::this_precomputed()
bool this_precomputed() const override
Expand All @@ -204,7 +204,7 @@ namespace libint2 {
/*
template <>
void
AlgebraicOperator<DGVertex>::add_exit_arc(const SafePtr<DGArc>& a)
AlgebraicOperator<DGVertex>::add_exit_arc(const std::shared_ptr<DGArc>& a)
{
DGVertex::add_exit_arc(a);
if (left_->equiv(a->dest()))
Expand Down
4 changes: 2 additions & 2 deletions src/bin/libint/bfset.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
namespace libint2 {

/** Set of basis functions. Sets must be constructable using
SafePtr<BFSet> or SafePtr<ConstructablePolymorphically>.
std::shared_ptr<BFSet> or std::shared_ptr<ConstructablePolymorphically>.
*/
class BFSet : public ConstructablePolymorphically {

Expand All @@ -52,7 +52,7 @@ namespace libint2 {
};

/** Set of basis functions with incrementable/decrementable quantum numbers.
Sets must be constructable using SafePtr<BFSet> or SafePtr<ConstructablePolymorphically>.
Sets must be constructable using std::shared_ptr<BFSet> or std::shared_ptr<ConstructablePolymorphically>.

Call to dec() may invalidate the object. No further
modification of such object's state is possible.
Expand Down
Loading
Loading