Przeglądaj źródła

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

main
offa 4 lat temu
rodzic
commit
61f27ad730
3 zmienionych plików z 31 dodań i 6 usunięć
  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 Wyświetl plik

@@ -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 Wyświetl plik

@@ -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 Wyświetl plik

@@ -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);
}

Ładowanie…
Anuluj
Zapisz