Bläddra i källkod

Conversion operator implemented.

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

+ 5
- 0
include/unique_resource.h Visa fil

@@ -85,6 +85,11 @@ namespace sr
return m_resource;
}

operator const Ressource&() const noexcept
{
return m_resource;
}


unique_resource_t& operator=(unique_resource_t&& other) noexcept
{

+ 8
- 1
test/UniqueResourceTest.cpp Visa fil

@@ -243,9 +243,16 @@ TEST_CASE("reset sets ressource", "[UniqueResource]")
REQUIRE(guard.get() == 7);
}

TEST_CASE("get returns ressource", "[UniqueResource]")
TEST_CASE("get accesses ressource", "[UniqueResource]")
{
auto guard = sr::unique_resource(Handle{3}, [](auto) { });
REQUIRE(guard.get() == 3);
}

TEST_CASE("conversion operator accesses ressource", "[UniqueResource]")
{
auto guard = sr::unique_resource(Handle{3}, [](auto) { });
const auto& ref = guard;
REQUIRE(ref == 3);
}


Laddar…
Avbryt
Spara