From f5880d4f57bc0d62639ac6ce90c2a6b6981368de Mon Sep 17 00:00:00 2001 From: Martin Moene Date: Fri, 27 Nov 2020 17:07:18 +0100 Subject: [PATCH] Add 'Tweak header' support via --- README.md | 4 +++- include/nonstd/any.hpp | 14 ++++++++++++++ test/CMakeLists.txt | 2 ++ test/any.t.cpp | 9 +++++++++ test/nonstd/any.tweak.hpp | 1 + test/t.bat | 2 +- test/tc.bat | 2 +- test/tg.bat | 2 +- 8 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 test/nonstd/any.tweak.hpp diff --git a/README.md b/README.md index dbdce07..b2f492c 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,8 @@ any: Allows to default construct any any: Allows to copy-construct from any any: Allows to move-construct from any (C++11) any: Allows to copy-construct from literal value -any: Allows to copy-construct from value +any: Allows to copy-construct from const value +any: Allows to copy-construct from lvalue references any: Allows to move-construct from value (C++11) any: Allows to in-place construct from literal value (C++11) any: Allows to in-place copy-construct from value (C++11) @@ -272,4 +273,5 @@ any_cast: Throws bad_any_cast if requested type differs from content type (any c any_cast: Throws bad_any_cast if requested type differs from content type (any &) any_cast: Throws bad_any_cast if requested type differs from content type (any &&) any_cast: Throws bad_any_cast with non-empty what() +tweak header: reads tweak header if supported [tweak] ``` diff --git a/include/nonstd/any.hpp b/include/nonstd/any.hpp index f921a77..7ec53e2 100644 --- a/include/nonstd/any.hpp +++ b/include/nonstd/any.hpp @@ -26,6 +26,20 @@ #define any_ANY_NONSTD 1 #define any_ANY_STD 2 +// tweak header support: + +#ifdef __has_include +# if __has_include() +# include +# endif +#define any_HAVE_TWEAK_HEADER 1 +#else +#define any_HAVE_TWEAK_HEADER 0 +//# pragma message("any.hpp: Note: Tweak header not supported.") +#endif + +// any selection and configuration: + #if !defined( any_CONFIG_SELECT_ANY ) # define any_CONFIG_SELECT_ANY ( any_HAVE_STD_ANY ? any_ANY_STD : any_ANY_NONSTD ) #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 919a49d..7c75639 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,7 @@ set( unit_name "any" ) set( PACKAGE ${unit_name}-lite ) set( PROGRAM ${unit_name}-lite ) set( SOURCES ${unit_name}-main.t.cpp ${unit_name}.t.cpp ) +set( TWEAKD "." ) message( STATUS "Subproject '${PROJECT_NAME}', programs '${PROGRAM}-*'") @@ -124,6 +125,7 @@ function( make_target target std ) message( STATUS "Make target: '${std}'" ) add_executable ( ${target} ${SOURCES} ) + target_include_directories( ${target} PRIVATE ${TWEAKD} ) target_link_libraries ( ${target} PRIVATE ${PACKAGE} ) target_compile_options ( ${target} PRIVATE ${OPTIONS} ) target_compile_definitions( ${target} PRIVATE ${DEFINITIONS} ) diff --git a/test/any.t.cpp b/test/any.t.cpp index fe28231..8250aed 100644 --- a/test/any.t.cpp +++ b/test/any.t.cpp @@ -662,4 +662,13 @@ CASE( "any_cast: Throws bad_any_cast with non-empty what()" ) } } +CASE( "tweak header: reads tweak header if supported " "[tweak]" ) +{ +#if any_HAVE_TWEAK_HEADER + EXPECT( ANY_TWEAK_VALUE == 42 ); +#else + EXPECT( !!"Tweak header is not available (any_HAVE_TWEAK_HEADER: 0)." ); +#endif +} + // end of file diff --git a/test/nonstd/any.tweak.hpp b/test/nonstd/any.tweak.hpp new file mode 100644 index 0000000..3ca1861 --- /dev/null +++ b/test/nonstd/any.tweak.hpp @@ -0,0 +1 @@ +#define ANY_TWEAK_VALUE 42 diff --git a/test/t.bat b/test/t.bat index d6f26c2..8a9f5ab 100644 --- a/test/t.bat +++ b/test/t.bat @@ -28,7 +28,7 @@ set msvc_defines=^ set CppCoreCheckInclude=%VCINSTALLDIR%\Auxiliary\VS\include -cl -W3 -EHsc %std% %unit_select% %unit_config% %msvc_defines% -I../include %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe +cl -W3 -EHsc %std% %unit_select% %unit_config% %msvc_defines% -I../include -I. %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe endlocal & goto :EOF :: subroutines: diff --git a/test/tc.bat b/test/tc.bat index ee8abc0..1d1ae0d 100644 --- a/test/tc.bat +++ b/test/tc.bat @@ -28,7 +28,7 @@ rem -flto / -fwhole-program set optflags=-O2 set warnflags=-Wall -Wextra -Wpedantic -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-missing-noreturn -Wno-documentation-unknown-command -Wno-documentation-deprecated-sync -Wno-documentation -Wno-weak-vtables -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-exit-time-destructors -Wno-global-constructors -"%clang%" -m32 -std=%std% %optflags% %warnflags% %unit_select% %unit_config% -fms-compatibility-version=19.00 -isystem "%VCInstallDir%include" -isystem "%WindowsSdkDir_71A%include" -I../include -o %unit%-main.t.exe %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe +"%clang%" -m32 -std=%std% %optflags% %warnflags% %unit_select% %unit_config% -fms-compatibility-version=19.00 -isystem "%VCInstallDir%include" -isystem "%WindowsSdkDir_71A%include" -I../include -I. -o %unit%-main.t.exe %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe endlocal & goto :EOF :: subroutines: diff --git a/test/tg.bat b/test/tg.bat index 6575387..edd0466 100644 --- a/test/tg.bat +++ b/test/tg.bat @@ -29,7 +29,7 @@ rem -flto / -fwhole-program set optflags=-O2 set warnflags=-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wno-padded -Wno-missing-noreturn -%gpp% -std=%std% %optflags% %warnflags% %unit_select% %unit_config% -o %unit%-main.t.exe -I../include %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe +%gpp% -std=%std% %optflags% %warnflags% %unit_select% %unit_config% -o %unit%-main.t.exe -I../include -I. %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe endlocal & goto :EOF