Pārlūkot izejas kodu

Conversion operator implemented.

main
offa pirms 7 gadiem
vecāks
revīzija
0d6173398c
2 mainītis faili ar 13 papildinājumiem un 1 dzēšanām
  1. +5
    -0
      include/unique_resource.h
  2. +8
    -1
      test/UniqueResourceTest.cpp

+ 5
- 0
include/unique_resource.h Parādīt failu

@@ -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 Parādīt failu

@@ -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);
}


Notiek ielāde…
Atcelt
Saglabāt