mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-13 19:18:01 +07:00
add fmt module for examples
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
@@ -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)
|
||||
|
||||
@@ -5,4 +5,6 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include <meta.hpp/meta_all.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
@@ -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<int> unique_int_variable;
|
||||
static const std::unique_ptr<int> 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<int> clazz_1::unique_int_variable = std::make_unique<int>(42);
|
||||
const std::unique_ptr<int> clazz_1::const_unique_int_variable = std::make_unique<int>(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<std::unique_ptr<int>*>());
|
||||
CHECK(vm.get_as<std::unique_ptr<int>*>() == std::addressof(clazz_1::unique_int_variable));
|
||||
CHECK(vm.get().get_type() == meta::resolve_type<unique_int*>());
|
||||
CHECK(vm.get_as<unique_int*>() == std::addressof(clazz_1::unique_int_variable));
|
||||
|
||||
{
|
||||
auto nv = std::make_unique<int>(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<int>(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<std::unique_ptr<int>>;
|
||||
using ref_t = std::reference_wrapper<unique_int>;
|
||||
CHECK(vm.get().get_type() == meta::resolve_type<ref_t>());
|
||||
CHECK(vm.get_as<ref_t>().get() == clazz_1::unique_int_variable);
|
||||
CHECK(&vm.get_as<ref_t>().get() == &clazz_1::unique_int_variable);
|
||||
|
||||
{
|
||||
auto nv = std::make_unique<int>(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<int>(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<const std::unique_ptr<int>*>());
|
||||
CHECK(vm.get_as<const std::unique_ptr<int>*>() == std::addressof(clazz_1::const_unique_int_variable));
|
||||
CHECK(vm.get().get_type() == meta::resolve_type<const unique_int*>());
|
||||
CHECK(vm.get_as<const unique_int*>() == std::addressof(clazz_1::const_unique_int_variable));
|
||||
|
||||
{
|
||||
auto nv = std::make_unique<int>(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<const std::unique_ptr<int>>;
|
||||
using ref_t = std::reference_wrapper<const unique_int>;
|
||||
CHECK(vm.get().get_type() == meta::resolve_type<ref_t>());
|
||||
CHECK(vm.get_as<ref_t>().get() == clazz_1::const_unique_int_variable);
|
||||
CHECK(&vm.get_as<ref_t>().get() == &clazz_1::const_unique_int_variable);
|
||||
|
||||
{
|
||||
auto nv = std::make_unique<int>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
develop/vendors/CMakeLists.txt
vendored
18
develop/vendors/CMakeLists.txt
vendored
@@ -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)
|
||||
|
||||
1
develop/vendors/fmt
vendored
Submodule
1
develop/vendors/fmt
vendored
Submodule
Submodule develop/vendors/fmt added at a33701196a
Reference in New Issue
Block a user