From 7c4f6e00353e435c74ef6c325fc4c7510484dbed Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 2 Jul 2021 08:16:25 +0700 Subject: [PATCH] fix msvc compilation --- headers/meta.hpp/meta_value.hpp | 6 ++++-- headers/meta.hpp/meta_variable_info.hpp | 8 ++++---- untests/meta_value_tests.cpp | 24 +++++++++++++----------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/headers/meta.hpp/meta_value.hpp b/headers/meta.hpp/meta_value.hpp index aa6a910..f4f7552 100644 --- a/headers/meta.hpp/meta_value.hpp +++ b/headers/meta.hpp/meta_value.hpp @@ -39,6 +39,7 @@ namespace meta_hpp public: bool to_bool() const { return cast(); } int to_int() const { return cast(); } + unsigned to_uint() const { return cast(); } float to_float() const { return cast(); } double to_double() const { return cast(); } std::string to_string() const { return cast(); } @@ -47,14 +48,15 @@ namespace meta_hpp std::int16_t to_int16() const { return cast(); } std::int32_t to_int32() const { return cast(); } std::int64_t to_int64() const { return cast(); } + std::ptrdiff_t to_ptrdiff_t() const { return cast(); } + std::intptr_t to_intptr_t() const { return cast(); } std::uint8_t to_uint8() const { return cast(); } std::uint16_t to_uint16() const { return cast(); } std::uint32_t to_uint32() const { return cast(); } std::uint64_t to_uint64() const { return cast(); } - std::size_t to_size_t() const { return cast(); } - std::ptrdiff_t to_ptrdiff_t() const { return cast(); } + std::uintptr_t to_uintptr_t() const { return cast(); } private: std::any raw_; }; diff --git a/headers/meta.hpp/meta_variable_info.hpp b/headers/meta.hpp/meta_variable_info.hpp index c407b3f..9e6b27b 100644 --- a/headers/meta.hpp/meta_variable_info.hpp +++ b/headers/meta.hpp/meta_variable_info.hpp @@ -23,14 +23,14 @@ namespace meta_hpp::variable_detail }; template < typename T > - struct variable_traits { + struct variable_traits + : variable_traits { static constexpr bool is_const = true; - using value_type = T; }; template < auto Variable > value getter() { - using vt = variable_traits; + using vt = variable_traits>; using value_type = typename vt::value_type; value_type typed_value = *Variable; @@ -40,7 +40,7 @@ namespace meta_hpp::variable_detail template < auto Variable > void setter(value value) { - using vt = variable_traits; + using vt = variable_traits>; using value_type = typename vt::value_type; if constexpr ( !vt::is_const ) { diff --git a/untests/meta_value_tests.cpp b/untests/meta_value_tests.cpp index 6e4a5aa..7de31cd 100644 --- a/untests/meta_value_tests.cpp +++ b/untests/meta_value_tests.cpp @@ -17,20 +17,22 @@ TEST_CASE("meta/value") { CHECK(meta::value{true}.to_bool() == true); CHECK(meta::value{1}.to_int() == 1); + CHECK(meta::value{1u}.to_uint() == 1u); CHECK(meta::value{1.f}.to_float() == 1.f); CHECK(meta::value{1.0}.to_double() == 1.0); CHECK(meta::value{"meta"s}.to_string() == "meta"); - CHECK(meta::value{std::in_place_type, 1}.to_int8() == 1); - CHECK(meta::value{std::in_place_type, 1}.to_int16() == 1); - CHECK(meta::value{std::in_place_type, 1}.to_int32() == 1); - CHECK(meta::value{std::in_place_type, 1}.to_int64() == 1); + CHECK(meta::value{std::in_place_type, std::int8_t{1}}.to_int8() == 1); + CHECK(meta::value{std::in_place_type, std::int16_t{1}}.to_int16() == 1); + CHECK(meta::value{std::in_place_type, std::int32_t{1}}.to_int32() == 1); + CHECK(meta::value{std::in_place_type, std::int64_t{1}}.to_int64() == 1); + CHECK(meta::value{std::in_place_type, std::ptrdiff_t{1}}.to_ptrdiff_t() == 1); + CHECK(meta::value{std::in_place_type, std::intptr_t{1}}.to_intptr_t() == 1); - CHECK(meta::value{std::in_place_type, 1}.to_uint8() == 1u); - CHECK(meta::value{std::in_place_type, 1}.to_uint16() == 1u); - CHECK(meta::value{std::in_place_type, 1}.to_uint32() == 1u); - CHECK(meta::value{std::in_place_type, 1}.to_uint64() == 1u); - - CHECK(meta::value{std::in_place_type, 1}.to_size_t() == 1u); - CHECK(meta::value{std::in_place_type, 1}.to_ptrdiff_t() == 1u); + CHECK(meta::value{std::in_place_type, std::uint8_t{1}}.to_uint8() == 1u); + CHECK(meta::value{std::in_place_type, std::uint16_t{1}}.to_uint16() == 1u); + CHECK(meta::value{std::in_place_type, std::uint32_t{1}}.to_uint32() == 1u); + CHECK(meta::value{std::in_place_type, std::uint64_t{1}}.to_uint64() == 1u); + CHECK(meta::value{std::in_place_type, std::size_t{1}}.to_size_t() == 1u); + CHECK(meta::value{std::in_place_type, std::uintptr_t{1}}.to_uintptr_t() == 1u); }