Selaa lähdekoodia

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

main
offa 4 vuotta sitten
vanhempi
commit
61f27ad730
3 muutettua tiedostoa jossa 31 lisäystä ja 6 poistoa
  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 Näytä tiedosto



template<class RR = R, class DD = D, template<class RR = R, class DD = D,
std::enable_if_t<(std::is_nothrow_move_assignable_v<RR> 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_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> unique_resource& operator=(unique_resource&& other) noexcept(std::is_nothrow_assignable_v<R&, R>
&& std::is_nothrow_assignable_v<D&, D>) && std::is_nothrow_assignable_v<D&, D>)
{ {
} }


} }



+ 20
- 0
test/CallMocks.h Näytä tiedosto

} }
}; };


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 Näytä tiedosto

TEST_CASE("std::function deleter", "[UniqueResource]") TEST_CASE("std::function deleter", "[UniqueResource]")
{ {
const auto deleter = std::function<void(Handle)>{[]([[maybe_unused]] Handle h) { }}; 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}; 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);
} }

Loading…
Peruuta
Tallenna