Przeglądaj źródła

Conversion operator implemented.

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

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

@@ -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 Wyświetl plik

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


Ładowanie…
Anuluj
Zapisz