Explorar el Código

Conversion operator implemented.

main
offa hace 7 años
padre
commit
0d6173398c
Se han modificado 2 ficheros con 13 adiciones y 1 borrados
  1. +5
    -0
      include/unique_resource.h
  2. +8
    -1
      test/UniqueResourceTest.cpp

+ 5
- 0
include/unique_resource.h Ver fichero

@@ -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 Ver fichero

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


Cargando…
Cancelar
Guardar