From a3b3ffa4ad58ef7cc18a4824b064adb8fe67d18e Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 13 Jan 2023 13:46:07 +0700 Subject: [PATCH] add fmt module for examples --- .gitmodules | 3 ++ develop/cmake/SetupTargets.cmake | 8 ++-- develop/manuals/meta_manuals.hpp | 2 + .../untests/meta_states/variable_tests.cpp | 48 ++++++++++++------- develop/vendors/CMakeLists.txt | 18 ++++++- develop/vendors/fmt | 1 + 6 files changed, 56 insertions(+), 24 deletions(-) create mode 160000 develop/vendors/fmt diff --git a/.gitmodules b/.gitmodules index 18ca32d..b0b35e4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendors/doctest"] path = develop/vendors/doctest url = https://github.com/onqtam/doctest +[submodule "develop/vendors/fmt"] + path = develop/vendors/fmt + url = https://github.com/fmtlib/fmt diff --git a/develop/cmake/SetupTargets.cmake b/develop/cmake/SetupTargets.cmake index 57af3fd..d5792c5 100644 --- a/develop/cmake/SetupTargets.cmake +++ b/develop/cmake/SetupTargets.cmake @@ -2,7 +2,8 @@ add_library(${PROJECT_NAME}.setup_targets INTERFACE) add_library(${PROJECT_NAME}::setup_targets ALIAS ${PROJECT_NAME}.setup_targets) target_link_libraries(${PROJECT_NAME}.setup_targets INTERFACE - meta.hpp.vendors::doctest) + meta.hpp.vendors::doctest + meta.hpp.vendors::fmt) target_compile_options(${PROJECT_NAME}.setup_targets INTERFACE $<$: @@ -14,13 +15,10 @@ target_compile_options(${PROJECT_NAME}.setup_targets INTERFACE -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-exit-time-destructors - -Wno-global-constructors -Wno-padded - -Wno-unneeded-internal-declaration - -Wno-unneeded-member-function -Wno-unused-macros + -Wno-unused-member-function -Wno-weak-vtables - -Wno-zero-as-null-pointer-constant >) if(BUILD_WITH_COVERAGE) diff --git a/develop/manuals/meta_manuals.hpp b/develop/manuals/meta_manuals.hpp index 4cc52f4..0f237c6 100644 --- a/develop/manuals/meta_manuals.hpp +++ b/develop/manuals/meta_manuals.hpp @@ -5,4 +5,6 @@ ******************************************************************************/ #include + #include +#include diff --git a/develop/untests/meta_states/variable_tests.cpp b/develop/untests/meta_states/variable_tests.cpp index a18776a..3504ed8 100644 --- a/develop/untests/meta_states/variable_tests.cpp +++ b/develop/untests/meta_states/variable_tests.cpp @@ -8,6 +8,18 @@ namespace { + struct unique_int { + int i{42}; + + unique_int() = default; + + unique_int(unique_int&&) = default; + unique_int& operator=(unique_int&&) = default; + + unique_int(const unique_int&) = delete; + unique_int& operator=(const unique_int&) = delete; + }; + struct clazz_1 { static int int_variable; static const int const_int_variable; @@ -15,8 +27,8 @@ namespace static int& ref_int_variable; static const int& const_ref_int_variable; - static std::unique_ptr unique_int_variable; - static const std::unique_ptr const_unique_int_variable; + static unique_int unique_int_variable; + static const unique_int const_unique_int_variable; }; int clazz_1::int_variable = 1; @@ -25,8 +37,8 @@ namespace int& clazz_1::ref_int_variable = clazz_1::int_variable; const int& clazz_1::const_ref_int_variable = clazz_1::const_int_variable; - std::unique_ptr clazz_1::unique_int_variable = std::make_unique(42); - const std::unique_ptr clazz_1::const_unique_int_variable = std::make_unique(42); + unique_int clazz_1::unique_int_variable; + const unique_int clazz_1::const_unique_int_variable; } TEST_CASE("meta/meta_states/variable") { @@ -164,19 +176,19 @@ TEST_CASE("meta/meta_states/variable") { meta::variable vm = clazz_1_type.get_variable("unique_int_variable_as_ptr"); REQUIRE(vm); - CHECK(vm.get().get_type() == meta::resolve_type*>()); - CHECK(vm.get_as*>() == std::addressof(clazz_1::unique_int_variable)); + CHECK(vm.get().get_type() == meta::resolve_type()); + CHECK(vm.get_as() == std::addressof(clazz_1::unique_int_variable)); { auto nv = std::make_unique(11); vm.set(std::move(nv)); - CHECK(*clazz_1::unique_int_variable == 11); + CHECK(clazz_1::unique_int_variable.i == 11); } { auto nv = std::make_unique(12); CHECK_THROWS(vm.set(nv)); - CHECK(*clazz_1::unique_int_variable == 11); + CHECK(clazz_1::unique_int_variable.i == 11); } } @@ -184,20 +196,20 @@ TEST_CASE("meta/meta_states/variable") { meta::variable vm = clazz_1_type.get_variable("unique_int_variable_as_ref"); REQUIRE(vm); - using ref_t = std::reference_wrapper>; + using ref_t = std::reference_wrapper; CHECK(vm.get().get_type() == meta::resolve_type()); - CHECK(vm.get_as().get() == clazz_1::unique_int_variable); + CHECK(&vm.get_as().get() == &clazz_1::unique_int_variable); { auto nv = std::make_unique(13); vm.set(std::move(nv)); - CHECK(*clazz_1::unique_int_variable == 13); + CHECK(clazz_1::unique_int_variable.i == 13); } { auto nv = std::make_unique(14); CHECK_THROWS(vm.set(nv)); - CHECK(*clazz_1::unique_int_variable == 13); + CHECK(clazz_1::unique_int_variable.i == 13); } } @@ -205,14 +217,14 @@ TEST_CASE("meta/meta_states/variable") { meta::variable vm = clazz_1_type.get_variable("const_unique_int_variable_as_ptr"); REQUIRE(vm); - CHECK(vm.get().get_type() == meta::resolve_type*>()); - CHECK(vm.get_as*>() == std::addressof(clazz_1::const_unique_int_variable)); + CHECK(vm.get().get_type() == meta::resolve_type()); + CHECK(vm.get_as() == std::addressof(clazz_1::const_unique_int_variable)); { auto nv = std::make_unique(11); CHECK_THROWS(vm.set(nv)); CHECK_THROWS(vm.set(std::move(nv))); - CHECK(*clazz_1::const_unique_int_variable == 42); + CHECK(clazz_1::const_unique_int_variable.i == 42); } } @@ -220,15 +232,15 @@ TEST_CASE("meta/meta_states/variable") { meta::variable vm = clazz_1_type.get_variable("const_unique_int_variable_as_ref"); REQUIRE(vm); - using ref_t = std::reference_wrapper>; + using ref_t = std::reference_wrapper; CHECK(vm.get().get_type() == meta::resolve_type()); - CHECK(vm.get_as().get() == clazz_1::const_unique_int_variable); + CHECK(&vm.get_as().get() == &clazz_1::const_unique_int_variable); { auto nv = std::make_unique(12); CHECK_THROWS(vm.set(nv)); CHECK_THROWS(vm.set(std::move(nv))); - CHECK(*clazz_1::const_unique_int_variable == 42); + CHECK(clazz_1::const_unique_int_variable.i == 42); } } } diff --git a/develop/vendors/CMakeLists.txt b/develop/vendors/CMakeLists.txt index f1b0db7..df35475 100644 --- a/develop/vendors/CMakeLists.txt +++ b/develop/vendors/CMakeLists.txt @@ -10,9 +10,25 @@ add_library(${PROJECT_NAME}::doctest ALIAS ${PROJECT_NAME}.doctest) target_compile_features(${PROJECT_NAME}.doctest PUBLIC cxx_std_20) -target_include_directories(${PROJECT_NAME}.doctest +target_include_directories(${PROJECT_NAME}.doctest SYSTEM PUBLIC doctest) target_compile_definitions(${PROJECT_NAME}.doctest PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN INTERFACE DOCTEST_CONFIG_USE_STD_HEADERS) + +# +# fmt +# + +add_library(${PROJECT_NAME}.fmt INTERFACE) +add_library(${PROJECT_NAME}::fmt ALIAS ${PROJECT_NAME}.fmt) + +target_compile_features(${PROJECT_NAME}.fmt + INTERFACE cxx_std_20) + +target_include_directories(${PROJECT_NAME}.fmt SYSTEM + INTERFACE fmt/include) + +target_compile_definitions(${PROJECT_NAME}.fmt + INTERFACE FMT_HEADER_ONLY) diff --git a/develop/vendors/fmt b/develop/vendors/fmt new file mode 160000 index 0000000..a337011 --- /dev/null +++ b/develop/vendors/fmt @@ -0,0 +1 @@ +Subproject commit a33701196adfad74917046096bf5a2aa0ab0bb50