Bladeren bron

Factory function make_unique_resource() fully implemented and Test

added.
main
offa 7 jaren geleden
bovenliggende
commit
0d2e3da347
2 gewijzigde bestanden met toevoegingen van 12 en 3 verwijderingen
  1. +5
    -3
      include/unique_resource.h
  2. +7
    -0
      test/UniqueResourceTest.cpp

+ 5
- 3
include/unique_resource.h Bestand weergeven

@@ -199,10 +199,12 @@ namespace sr
};


template<class Resource, class Deleter>
unique_resource<std::decay_t<Resource>, std::decay_t<Deleter>> make_unique_resource(Resource&& r, Deleter&& d)
template<class R, class D>
unique_resource<std::decay_t<R>, std::decay_t<D>> make_unique_resource(R&& r, D&& d)
noexcept(std::is_nothrow_constructible<std::decay_t<R>, R>::value
&& std::is_nothrow_constructible<std::decay_t<D>, D>::value)
{
return unique_resource<std::decay_t<Resource>, std::decay_t<Deleter>>{std::forward<Resource>(r), std::forward<Deleter>(d)};
return unique_resource<std::decay_t<R>, std::decay_t<D>>{std::forward<R>(r), std::forward<D>(d)};
}



+ 7
- 0
test/UniqueResourceTest.cpp Bestand weergeven

@@ -258,3 +258,10 @@ TEST_CASE("deleter access", "[UniqueResource]")
}
}

TEST_CASE("make unique resource", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(7));
auto guard = sr::make_unique_resource(Handle{7}, deleter);
static_cast<void>(guard);
}


Laden…
Annuleren
Opslaan