diff options
-rw-r--r-- | include/gsl/util | 2 | ||||
-rw-r--r-- | tests/utils_tests.cpp | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/include/gsl/util b/include/gsl/util index db6a85e..75c78ad 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -87,7 +87,7 @@ private: template <class F> GSL_NODISCARD auto finally(F&& f) noexcept { - return final_action<std::remove_cv_t<std::remove_reference_t<F>>>{std::forward<F>(f)}; + return final_action<std::decay_t<F>>{std::forward<F>(f)}; } // narrow_cast(): a searchable way to do narrowing casts of values diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp index 715073f..7e1e77d 100644 --- a/tests/utils_tests.cpp +++ b/tests/utils_tests.cpp @@ -112,6 +112,16 @@ TEST(utils_tests, finally_function_ptr) EXPECT_TRUE(j == 1); } +TEST(utils_tests, finally_function) +{ + j = 0; + { + auto _ = finally(g); + EXPECT_TRUE(j == 0); + } + EXPECT_TRUE(j == 1); +} + TEST(utils_tests, narrow_cast) { int n = 120; |