diff --git a/README.md b/README.md index 75a11c3..0244148 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,12 @@ target_link_libraries(your_project_target defer.hpp) ### Basic Defer ```cpp -if ( FILE *file = ::fopen("output.txt", "a") ) { +if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ ::fclose(file); }); + DEFER([file]{ std::fclose(file); }); const char buffer[] = "hello world\n"; - if ( 12 != ::fwrite(buffer, sizeof(buffer[0]), ::strlen(buffer), file) ) { + if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { throw std::runtime_error("some exception"); } } @@ -63,9 +63,9 @@ if ( FILE *file = ::fopen("output.txt", "a") ) { ### Error Defer ```cpp -if ( FILE *file = ::fopen("output.txt", "a") ) { +if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ ::fclose(file); }); + DEFER([file]{ std::fclose(file); }); // error defer will be called on exception ERROR_DEFER([]{ @@ -73,7 +73,7 @@ if ( FILE *file = ::fopen("output.txt", "a") ) { }); const char buffer[] = "hello world\n"; - if ( 12 != ::fwrite(buffer, sizeof(buffer[0]), ::strlen(buffer), file) ) { + if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { throw std::runtime_error("some exception"); } } @@ -82,9 +82,9 @@ if ( FILE *file = ::fopen("output.txt", "a") ) { ### Return Defer ```cpp -if ( FILE *file = ::fopen("output.txt", "a") ) { +if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ ::fclose(file); }); + DEFER([file]{ std::fclose(file); }); // return defer will be called on successful scope exit RETURN_DEFER([]{ @@ -92,7 +92,7 @@ if ( FILE *file = ::fopen("output.txt", "a") ) { }); const char buffer[] = "hello world\n"; - if ( 12 != ::fwrite(buffer, sizeof(buffer[0]), ::strlen(buffer), file) ) { + if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { throw std::runtime_error("some exception"); } } diff --git a/untests/defer_examples.cpp b/untests/defer_examples.cpp index e7e53bf..b1a4dc8 100644 --- a/untests/defer_examples.cpp +++ b/untests/defer_examples.cpp @@ -7,26 +7,29 @@ #define CATCH_CONFIG_FAST_COMPILE #include +#include +#include #include + #include TEST_CASE("examples") { SECTION("basic_defer") { - if ( FILE *file = ::fopen("output.txt", "a") ) { + if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ ::fclose(file); }); + DEFER([file]{ std::fclose(file); }); const char buffer[] = "hello world\n"; - if ( 12 != ::fwrite(buffer, sizeof(buffer[0]), ::strlen(buffer), file) ) { + if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { throw std::runtime_error("some exception"); } } } SECTION("error_defer") { - if ( FILE *file = ::fopen("output.txt", "a") ) { + if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ ::fclose(file); }); + DEFER([file]{ std::fclose(file); }); // error defer will be called on exception ERROR_DEFER([]{ @@ -34,16 +37,16 @@ TEST_CASE("examples") { }); const char buffer[] = "hello world\n"; - if ( 12 != ::fwrite(buffer, sizeof(buffer[0]), ::strlen(buffer), file) ) { + if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { throw std::runtime_error("some exception"); } } } SECTION("return_defer") { - if ( FILE *file = ::fopen("output.txt", "a") ) { + if ( FILE *file = std::fopen("output.txt", "a") ) { // defer will close the file after scope or on exception - DEFER([file]{ ::fclose(file); }); + DEFER([file]{ std::fclose(file); }); // return defer will be called on successful scope exit RETURN_DEFER([]{ @@ -51,7 +54,7 @@ TEST_CASE("examples") { }); const char buffer[] = "hello world\n"; - if ( 12 != ::fwrite(buffer, sizeof(buffer[0]), ::strlen(buffer), file) ) { + if ( 12 != std::fwrite(buffer, sizeof(buffer[0]), std::strlen(buffer), file) ) { throw std::runtime_error("some exception"); } }