fix msvc compilation

This commit is contained in:
BlackMATov
2021-07-02 08:16:25 +07:00
parent ce7f7d0beb
commit 7c4f6e0035
3 changed files with 21 additions and 17 deletions

View File

@@ -39,6 +39,7 @@ namespace meta_hpp
public:
bool to_bool() const { return cast<bool>(); }
int to_int() const { return cast<int>(); }
unsigned to_uint() const { return cast<unsigned>(); }
float to_float() const { return cast<float>(); }
double to_double() const { return cast<double>(); }
std::string to_string() const { return cast<std::string>(); }
@@ -47,14 +48,15 @@ namespace meta_hpp
std::int16_t to_int16() const { return cast<std::int16_t>(); }
std::int32_t to_int32() const { return cast<std::int32_t>(); }
std::int64_t to_int64() const { return cast<std::int64_t>(); }
std::ptrdiff_t to_ptrdiff_t() const { return cast<std::ptrdiff_t>(); }
std::intptr_t to_intptr_t() const { return cast<std::intptr_t>(); }
std::uint8_t to_uint8() const { return cast<std::uint8_t>(); }
std::uint16_t to_uint16() const { return cast<std::uint16_t>(); }
std::uint32_t to_uint32() const { return cast<std::uint32_t>(); }
std::uint64_t to_uint64() const { return cast<std::uint64_t>(); }
std::size_t to_size_t() const { return cast<std::size_t>(); }
std::ptrdiff_t to_ptrdiff_t() const { return cast<std::ptrdiff_t>(); }
std::uintptr_t to_uintptr_t() const { return cast<std::uintptr_t>(); }
private:
std::any raw_;
};

View File

@@ -23,14 +23,14 @@ namespace meta_hpp::variable_detail
};
template < typename T >
struct variable_traits<const T*> {
struct variable_traits<const T*>
: variable_traits<T*> {
static constexpr bool is_const = true;
using value_type = T;
};
template < auto Variable >
value getter() {
using vt = variable_traits<decltype(Variable)>;
using vt = variable_traits<std::remove_reference_t<decltype(Variable)>>;
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<decltype(Variable)>;
using vt = variable_traits<std::remove_reference_t<decltype(Variable)>>;
using value_type = typename vt::value_type;
if constexpr ( !vt::is_const ) {

View File

@@ -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<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::int8_t>, std::int8_t{1}}.to_int8() == 1);
CHECK(meta::value{std::in_place_type<std::int16_t>, std::int16_t{1}}.to_int16() == 1);
CHECK(meta::value{std::in_place_type<std::int32_t>, std::int32_t{1}}.to_int32() == 1);
CHECK(meta::value{std::in_place_type<std::int64_t>, std::int64_t{1}}.to_int64() == 1);
CHECK(meta::value{std::in_place_type<std::ptrdiff_t>, std::ptrdiff_t{1}}.to_ptrdiff_t() == 1);
CHECK(meta::value{std::in_place_type<std::intptr_t>, std::intptr_t{1}}.to_intptr_t() == 1);
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::ptrdiff_t>, 1}.to_ptrdiff_t() == 1u);
CHECK(meta::value{std::in_place_type<std::uint8_t>, std::uint8_t{1}}.to_uint8() == 1u);
CHECK(meta::value{std::in_place_type<std::uint16_t>, std::uint16_t{1}}.to_uint16() == 1u);
CHECK(meta::value{std::in_place_type<std::uint32_t>, std::uint32_t{1}}.to_uint32() == 1u);
CHECK(meta::value{std::in_place_type<std::uint64_t>, std::uint64_t{1}}.to_uint64() == 1u);
CHECK(meta::value{std::in_place_type<std::size_t>, std::size_t{1}}.to_size_t() == 1u);
CHECK(meta::value{std::in_place_type<std::uintptr_t>, std::uintptr_t{1}}.to_uintptr_t() == 1u);
}