Bläddra i källkod

Pointer access added.

main
offa 7 år sedan
förälder
incheckning
105766eff4
2 ändrade filer med 14 tillägg och 1 borttagningar
  1. +7
    -0
      include/unique_resource.h
  2. +7
    -1
      test/UniqueResourceTest.cpp

+ 7
- 0
include/unique_resource.h Visa fil

@@ -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 Visa fil

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

Laddar…
Avbryt
Spara