Sfoglia il codice sorgente

Pointer access added.

main
offa 7 anni fa
parent
commit
105766eff4
2 ha cambiato i file con 14 aggiunte e 1 eliminazioni
  1. +7
    -0
      include/unique_resource.h
  2. +7
    -1
      test/UniqueResourceTest.cpp

+ 7
- 0
include/unique_resource.h Vedi File

@@ -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 Vedi File

@@ -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]")
{

Loading…
Annulla
Salva