Skip to content

Commit

Permalink
Merge Fix Typo Clonable
Browse files Browse the repository at this point in the history
This merge fixes the typo `clonable -> cloneable`. This has no interface changes.

Related PR: #1686
  • Loading branch information
MarcelKoch authored Oct 2, 2024
2 parents b5745ac + 10d0dd4 commit e518aee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
32 changes: 16 additions & 16 deletions core/test/base/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ TEST(PointerParam, WorksForUniquePointers)
}


struct ClonableDerived : Base {
ClonableDerived(std::shared_ptr<const gko::Executor> exec = nullptr)
struct CloneableDerived : Base {
CloneableDerived(std::shared_ptr<const gko::Executor> exec = nullptr)
: executor(exec)
{}

std::unique_ptr<Base> clone()
{
return std::unique_ptr<Base>(new ClonableDerived());
return std::unique_ptr<Base>(new CloneableDerived());
}

std::unique_ptr<Base> clone(std::shared_ptr<const gko::Executor> exec)
{
return std::unique_ptr<Base>(new ClonableDerived{exec});
return std::unique_ptr<Base>(new CloneableDerived{exec});
}

std::shared_ptr<const gko::Executor> executor;
Expand All @@ -104,49 +104,49 @@ struct ClonableDerived : Base {

TEST(Clone, ClonesUniquePointer)
{
std::unique_ptr<ClonableDerived> p(new ClonableDerived());
std::unique_ptr<CloneableDerived> p(new CloneableDerived());

auto clone = gko::clone(p);

::testing::StaticAssertTypeEq<decltype(clone),
std::unique_ptr<ClonableDerived>>();
std::unique_ptr<CloneableDerived>>();
ASSERT_NE(p.get(), clone.get());
}


TEST(Clone, ClonesSharedPointer)
{
std::shared_ptr<ClonableDerived> p(new ClonableDerived());
std::shared_ptr<CloneableDerived> p(new CloneableDerived());

auto clone = gko::clone(p);

::testing::StaticAssertTypeEq<decltype(clone),
std::unique_ptr<ClonableDerived>>();
std::unique_ptr<CloneableDerived>>();
ASSERT_NE(p.get(), clone.get());
}


TEST(Clone, ClonesPlainPointer)
{
std::unique_ptr<ClonableDerived> p(new ClonableDerived());
std::unique_ptr<CloneableDerived> p(new CloneableDerived());

auto clone = gko::clone(p.get());

::testing::StaticAssertTypeEq<decltype(clone),
std::unique_ptr<ClonableDerived>>();
std::unique_ptr<CloneableDerived>>();
ASSERT_NE(p.get(), clone.get());
}


TEST(CloneTo, ClonesUniquePointer)
{
auto exec = gko::ReferenceExecutor::create();
std::unique_ptr<ClonableDerived> p(new ClonableDerived());
std::unique_ptr<CloneableDerived> p(new CloneableDerived());

auto clone = gko::clone(exec, p);

::testing::StaticAssertTypeEq<decltype(clone),
std::unique_ptr<ClonableDerived>>();
std::unique_ptr<CloneableDerived>>();
ASSERT_NE(p.get(), clone.get());
ASSERT_EQ(clone->executor, exec);
}
Expand All @@ -155,12 +155,12 @@ TEST(CloneTo, ClonesUniquePointer)
TEST(CloneTo, ClonesSharedPointer)
{
auto exec = gko::ReferenceExecutor::create();
std::shared_ptr<ClonableDerived> p(new ClonableDerived());
std::shared_ptr<CloneableDerived> p(new CloneableDerived());

auto clone = gko::clone(exec, p);

::testing::StaticAssertTypeEq<decltype(clone),
std::unique_ptr<ClonableDerived>>();
std::unique_ptr<CloneableDerived>>();
ASSERT_NE(p.get(), clone.get());
ASSERT_EQ(clone->executor, exec);
}
Expand All @@ -169,12 +169,12 @@ TEST(CloneTo, ClonesSharedPointer)
TEST(CloneTo, ClonesPlainPointer)
{
auto exec = gko::ReferenceExecutor::create();
std::unique_ptr<ClonableDerived> p(new ClonableDerived());
std::unique_ptr<CloneableDerived> p(new CloneableDerived());

auto clone = gko::clone(exec, p.get());

::testing::StaticAssertTypeEq<decltype(clone),
std::unique_ptr<ClonableDerived>>();
std::unique_ptr<CloneableDerived>>();
ASSERT_NE(p.get(), clone.get());
ASSERT_EQ(clone->executor, exec);
}
Expand Down
24 changes: 12 additions & 12 deletions include/ginkgo/core/base/utils_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,32 @@ using pointee =


template <typename T, typename = void>
struct is_clonable_impl : std::false_type {};
struct is_cloneable_impl : std::false_type {};

template <typename T>
struct is_clonable_impl<T, std::void_t<decltype(std::declval<T>().clone())>>
struct is_cloneable_impl<T, std::void_t<decltype(std::declval<T>().clone())>>
: std::true_type {};

template <typename T>
constexpr bool is_clonable()
constexpr bool is_cloneable()
{
return is_clonable_impl<std::decay_t<T>>::value;
return is_cloneable_impl<std::decay_t<T>>::value;
}


template <typename T, typename = void>
struct is_clonable_to_impl : std::false_type {};
struct is_cloneable_to_impl : std::false_type {};

template <typename T>
struct is_clonable_to_impl<
struct is_cloneable_to_impl<
T, std::void_t<decltype(std::declval<T>().clone(
std::declval<std::shared_ptr<const Executor>>()))>>
: std::true_type {};

template <typename T>
constexpr bool is_clonable_to()
constexpr bool is_cloneable_to()
{
return is_clonable_to_impl<std::decay_t<T>>::value;
return is_cloneable_to_impl<std::decay_t<T>>::value;
}


Expand Down Expand Up @@ -172,8 +172,8 @@ using shared_type = std::shared_ptr<pointee<Pointer>>;
template <typename Pointer>
inline detail::cloned_type<Pointer> clone(const Pointer& p)
{
static_assert(detail::is_clonable<detail::pointee<Pointer>>(),
"Object is not clonable");
static_assert(detail::is_cloneable<detail::pointee<Pointer>>(),
"Object is not cloneable");
return detail::cloned_type<Pointer>(
static_cast<typename std::remove_cv<detail::pointee<Pointer>>::type*>(
p->clone().release()));
Expand All @@ -199,8 +199,8 @@ template <typename Pointer>
inline detail::cloned_type<Pointer> clone(std::shared_ptr<const Executor> exec,
const Pointer& p)
{
static_assert(detail::is_clonable_to<detail::pointee<Pointer>>(),
"Object is not clonable");
static_assert(detail::is_cloneable_to<detail::pointee<Pointer>>(),
"Object is not cloneable");
return detail::cloned_type<Pointer>(
static_cast<typename std::remove_cv<detail::pointee<Pointer>>::type*>(
p->clone(std::move(exec)).release()));
Expand Down

0 comments on commit e518aee

Please sign in to comment.