Przeglądaj źródła

Pointer access added.

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

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

@@ -159,6 +159,13 @@ namespace sr
return m_resource;
}

template<class RR = R,
std::enable_if_t<std::is_pointer<RR>::value, int> = 0>
std::add_lvalue_reference_t<std::remove_pointer_t<RR>> operator*() const noexcept
{
return *get();
}

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

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

@@ -229,7 +229,13 @@ TEST_CASE("pointer access resturns resource" "[UniqueResource]")
REQUIRE(guard->first == 3);
REQUIRE(guard->second == 4);
}
// TODO: Pointer access functions

TEST_CASE("pointer dereference resturns resource" "[UniqueResource]")
{
Handle h{5};
auto guard = sr::make_unique_resource(PtrHandle{&h}, [](auto*) { });
REQUIRE(*guard == 5);
}

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

Ładowanie…
Anuluj
Zapisz