浏览代码

Type requirement of unique_resource::operator=() fixed (#171).

main
offa 4 年前
父节点
当前提交
61f27ad730
共有 3 个文件被更改,包括 31 次插入6 次删除
  1. +2
    -4
      include/unique_resource.h
  2. +20
    -0
      test/CallMocks.h
  3. +9
    -2
      test/UniqueResourceTest.cpp

+ 2
- 4
include/unique_resource.h 查看文件

@@ -149,9 +149,9 @@ namespace sr

template<class RR = R, class DD = D,
std::enable_if_t<(std::is_nothrow_move_assignable_v<RR>
|| std::is_nothrow_copy_assignable_v<RR>)
|| std::is_copy_assignable_v<RR>)
&& (std::is_nothrow_move_assignable_v<DD>
|| std::is_nothrow_copy_assignable_v<DD>), int> = 0>
|| std::is_copy_assignable_v<DD>), int> = 0>
unique_resource& operator=(unique_resource&& other) noexcept(std::is_nothrow_assignable_v<R&, R>
&& std::is_nothrow_assignable_v<D&, D>)
{
@@ -222,5 +222,3 @@ namespace sr
}

}



+ 20
- 0
test/CallMocks.h 查看文件

@@ -249,5 +249,25 @@ namespace mock
}
};

struct FunctionDeleter
{
FunctionDeleter() noexcept = default;
FunctionDeleter(const FunctionDeleter&) = default;
FunctionDeleter(FunctionDeleter&&) = default;

FunctionDeleter& operator=(const FunctionDeleter&)
{
return *this;
}

FunctionDeleter& operator=(FunctionDeleter&&)
{
return *this;
}

void operator()(Handle) const
{
}
};

}

+ 9
- 2
test/UniqueResourceTest.cpp 查看文件

@@ -241,7 +241,14 @@ TEST_CASE("noexcept move", "[UniqueResource]")
TEST_CASE("std::function deleter", "[UniqueResource]")
{
const auto deleter = std::function<void(Handle)>{[]([[maybe_unused]] Handle h) { }};
sr::unique_resource guard1{Handle{3}, deleter};
sr::unique_resource movedFrom{Handle{3}, deleter};
sr::unique_resource guard2{Handle{4}, deleter};
guard2 = std::move(guard1);
guard2 = std::move(movedFrom);
}

TEST_CASE("not noexcept move and copy assignable deleter", "[UniqueResource]")
{
sr::unique_resource movedFrom{0, FunctionDeleter{}};
sr::unique_resource guard{0, FunctionDeleter{}};
guard = std::move(movedFrom);
}

正在加载...
取消
保存