From 9fbd7a34cf100ed26d6486650fb1498bdc33a861 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 29 Oct 2020 04:58:07 +0700 Subject: [PATCH] rename DEFER to DEFER_HPP --- README.md | 10 +++++----- headers/defer.hpp/defer.hpp | 28 ++++++++++++++-------------- untests/defer_examples.cpp | 10 +++++----- untests/defer_tests.cpp | 24 ++++++++++++------------ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 0244148..9e08bda 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ target_link_libraries(your_project_target defer.hpp) ```cpp if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ std::fclose(file); }); + DEFER_HPP([file]{ std::fclose(file); }); const char buffer[] = "hello world\n"; if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { @@ -65,10 +65,10 @@ if ( FILE *file = std::fopen("output.txt", "a") ) { ```cpp if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ std::fclose(file); }); + DEFER_HPP([file]{ std::fclose(file); }); // error defer will be called on exception - ERROR_DEFER([]{ + ERROR_DEFER_HPP([]{ std::cerr << "there is something wrong" << std::endl; }); @@ -84,10 +84,10 @@ if ( FILE *file = std::fopen("output.txt", "a") ) { ```cpp if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ std::fclose(file); }); + DEFER_HPP([file]{ std::fclose(file); }); // return defer will be called on successful scope exit - RETURN_DEFER([]{ + RETURN_DEFER_HPP([]{ std::cout << "all is ok!" << std::endl; }); diff --git a/headers/defer.hpp/defer.hpp b/headers/defer.hpp/defer.hpp index fae4a72..192588c 100644 --- a/headers/defer.hpp/defer.hpp +++ b/headers/defer.hpp/defer.hpp @@ -120,31 +120,31 @@ namespace defer_hpp } } -#define DEFER_IMPL_PP_CAT(x, y) DEFER_IMPL_PP_CAT_I(x, y) -#define DEFER_IMPL_PP_CAT_I(x, y) x ## y +#define DEFER_HPP_IMPL_PP_CAT(x, y) DEFER_HPP_IMPL_PP_CAT_I(x, y) +#define DEFER_HPP_IMPL_PP_CAT_I(x, y) x ## y #ifdef __COUNTER__ - #define DEFER(...)\ - auto DEFER_IMPL_PP_CAT(generated_defer_, __COUNTER__) =\ + #define DEFER_HPP(...)\ + auto DEFER_HPP_IMPL_PP_CAT(generated_defer_, __COUNTER__) =\ ::defer_hpp::make_defer(__VA_ARGS__) - #define ERROR_DEFER(...)\ - auto DEFER_IMPL_PP_CAT(generated_error_defer_, __COUNTER__) =\ + #define ERROR_DEFER_HPP(...)\ + auto DEFER_HPP_IMPL_PP_CAT(generated_error_defer_, __COUNTER__) =\ ::defer_hpp::make_error_defer(__VA_ARGS__) - #define RETURN_DEFER(...)\ - auto DEFER_IMPL_PP_CAT(generated_return_defer_, __COUNTER__) =\ + #define RETURN_DEFER_HPP(...)\ + auto DEFER_HPP_IMPL_PP_CAT(generated_return_defer_, __COUNTER__) =\ ::defer_hpp::make_return_defer(__VA_ARGS__) #else - #define DEFER(...)\ - auto DEFER_IMPL_PP_CAT(generated_defer_, __LINE__) =\ + #define DEFER_HPP(...)\ + auto DEFER_HPP_IMPL_PP_CAT(generated_defer_, __LINE__) =\ ::defer_hpp::make_defer(__VA_ARGS__) - #define ERROR_DEFER(...)\ - auto DEFER_IMPL_PP_CAT(generated_error_defer_, __LINE__) =\ + #define ERROR_DEFER_HPP(...)\ + auto DEFER_HPP_IMPL_PP_CAT(generated_error_defer_, __LINE__) =\ ::defer_hpp::make_error_defer(__VA_ARGS__) - #define RETURN_DEFER(...)\ - auto DEFER_IMPL_PP_CAT(generated_return_defer_, __LINE__) =\ + #define RETURN_DEFER_HPP(...)\ + auto DEFER_HPP_IMPL_PP_CAT(generated_return_defer_, __LINE__) =\ ::defer_hpp::make_return_defer(__VA_ARGS__) #endif diff --git a/untests/defer_examples.cpp b/untests/defer_examples.cpp index b1a4dc8..f8932ed 100644 --- a/untests/defer_examples.cpp +++ b/untests/defer_examples.cpp @@ -17,7 +17,7 @@ TEST_CASE("examples") { SECTION("basic_defer") { if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ std::fclose(file); }); + DEFER_HPP([file]{ std::fclose(file); }); const char buffer[] = "hello world\n"; if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { @@ -29,10 +29,10 @@ TEST_CASE("examples") { SECTION("error_defer") { if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ std::fclose(file); }); + DEFER_HPP([file]{ std::fclose(file); }); // error defer will be called on exception - ERROR_DEFER([]{ + ERROR_DEFER_HPP([]{ std::cerr << "there is something wrong" << std::endl; }); @@ -46,10 +46,10 @@ TEST_CASE("examples") { SECTION("return_defer") { if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ std::fclose(file); }); + DEFER_HPP([file]{ std::fclose(file); }); // return defer will be called on successful scope exit - RETURN_DEFER([]{ + RETURN_DEFER_HPP([]{ std::cout << "all is ok!" << std::endl; }); diff --git a/untests/defer_tests.cpp b/untests/defer_tests.cpp index 7217e24..d5291b7 100644 --- a/untests/defer_tests.cpp +++ b/untests/defer_tests.cpp @@ -17,7 +17,7 @@ TEST_CASE("defer") { SECTION("simple") { int i = 0; { - DEFER([&i]{ ++i; }); + DEFER_HPP([&i]{ ++i; }); REQUIRE(i == 0); } REQUIRE(i == 1); @@ -26,7 +26,7 @@ TEST_CASE("defer") { SECTION("simple_with_arg") { int i = 0; { - DEFER([](int& i){ ++i; }, std::ref(i)); + DEFER_HPP([](int& i){ ++i; }, std::ref(i)); REQUIRE(i == 0); } REQUIRE(i == 1); @@ -35,7 +35,7 @@ TEST_CASE("defer") { SECTION("simple_with_args") { int i = 0, j = 0; { - DEFER([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j)); + DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j)); REQUIRE(i == 0); REQUIRE(j == 0); } @@ -46,7 +46,7 @@ TEST_CASE("defer") { SECTION("simple_with_exception") { int i = 0; try { - DEFER([&i]{ ++i; }); + DEFER_HPP([&i]{ ++i; }); REQUIRE(i == 0); throw std::exception(); } catch (...) { @@ -59,7 +59,7 @@ TEST_CASE("error_defer") { SECTION("simple") { int i = 0; { - ERROR_DEFER([&i]{ ++i; }); + ERROR_DEFER_HPP([&i]{ ++i; }); REQUIRE(i == 0); } REQUIRE(i == 0); @@ -68,7 +68,7 @@ TEST_CASE("error_defer") { SECTION("simple_with_arg") { int i = 0; { - ERROR_DEFER([](int& i){ ++i; }, std::ref(i)); + ERROR_DEFER_HPP([](int& i){ ++i; }, std::ref(i)); REQUIRE(i == 0); } REQUIRE(i == 0); @@ -77,7 +77,7 @@ TEST_CASE("error_defer") { SECTION("simple_with_args") { int i = 0, j = 0; { - ERROR_DEFER([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j)); + ERROR_DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j)); REQUIRE(i == 0); REQUIRE(j == 0); } @@ -88,7 +88,7 @@ TEST_CASE("error_defer") { SECTION("simple_with_exception") { int i = 0; try { - ERROR_DEFER([&i]{ ++i; }); + ERROR_DEFER_HPP([&i]{ ++i; }); REQUIRE(i == 0); throw std::exception(); } catch (...) { @@ -101,7 +101,7 @@ TEST_CASE("return_defer") { SECTION("simple") { int i = 0; { - RETURN_DEFER([&i]{ ++i; }); + RETURN_DEFER_HPP([&i]{ ++i; }); REQUIRE(i == 0); } REQUIRE(i == 1); @@ -110,7 +110,7 @@ TEST_CASE("return_defer") { SECTION("simple_with_arg") { int i = 0; { - RETURN_DEFER([](int& i){ ++i; }, std::ref(i)); + RETURN_DEFER_HPP([](int& i){ ++i; }, std::ref(i)); REQUIRE(i == 0); } REQUIRE(i == 1); @@ -119,7 +119,7 @@ TEST_CASE("return_defer") { SECTION("simple_with_args") { int i = 0, j = 0; { - RETURN_DEFER([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j)); + RETURN_DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j)); REQUIRE(i == 0); REQUIRE(j == 0); } @@ -130,7 +130,7 @@ TEST_CASE("return_defer") { SECTION("simple_with_exception") { int i = 0; try { - RETURN_DEFER([&i]{ ++i; }); + RETURN_DEFER_HPP([&i]{ ++i; }); REQUIRE(i == 0); throw std::exception(); } catch (...) {