Przeglądaj źródła

Pointer access added.

main
offa 7 lat temu
rodzic
commit
fc66bf69dc
2 zmienionych plików z 17 dodań i 0 usunięć
  1. +10
    -0
      include/unique_resource.h
  2. +7
    -0
      test/UniqueResourceTest.cpp

+ 10
- 0
include/unique_resource.h Wyświetl plik

return m_resource; return m_resource;
} }


template<class RR = R,
std::enable_if_t<std::is_pointer<RR>::value && std::is_nothrow_copy_constructible<RR>::value
&& ( std::is_class<std::remove_pointer_t<RR>>::value
|| std::is_union<std::remove_pointer_t<RR>>::value ), int> = 0
>
RR operator->() const noexcept
{
return m_resource;
}

const D& get_deleter() const noexcept const D& get_deleter() const noexcept
{ {
return m_deleter; return m_deleter;

+ 7
- 0
test/UniqueResourceTest.cpp Wyświetl plik

CHECK(guard.get() == 3); CHECK(guard.get() == 3);
} }


TEST_CASE("pointer access resturns resource" "[UniqueResource]")
{
const auto p = std::make_pair(3, 4);
auto guard = sr::make_unique_resource(&p, [](auto*) { });
REQUIRE(guard->first == 3);
REQUIRE(guard->second == 4);
}
// TODO: Pointer access functions // TODO: Pointer access functions


TEST_CASE("deleter access", "[UniqueResource]") TEST_CASE("deleter access", "[UniqueResource]")

Ładowanie…
Anuluj
Zapisz