Merge pull request #55 from BlackMATov/dev

Dev
This commit is contained in:
2023-02-09 19:26:14 +07:00
committed by GitHub
67 changed files with 2575 additions and 3213 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,65 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include <meta.hpp/meta_all.hpp>
#include <doctest/doctest.h>
namespace
{
struct ivec2 {
int x{};
int y{};
ivec2& add(const ivec2& other) {
x += other.x;
y += other.y;
return *this;
}
};
}
TEST_CASE("meta/meta_indices/ops/_") {
namespace meta = meta_hpp;
meta::class_<ivec2>()
.member_("x", &ivec2::x)
.member_("y", &ivec2::y)
.method_("add", &ivec2::add);
}
TEST_CASE("meta/meta_indices/ops") {
namespace meta = meta_hpp;
const meta::class_type ivec2_type = meta::resolve_type<ivec2>();
REQUIRE(ivec2_type);
const meta::member ivec2_x = ivec2_type.get_member("x");
REQUIRE(ivec2_x);
const meta::member ivec2_y = ivec2_type.get_member("y");
REQUIRE(ivec2_y);
const meta::method ivec2_add = ivec2_type.get_method("add");
REQUIRE(ivec2_add);
SUBCASE("get_type") {
CHECK(ivec2_x.get_index().get_type() == meta::resolve_type<int ivec2::*>());
CHECK(ivec2_add.get_index().get_type() == meta::resolve_type<ivec2& (ivec2::*)(const ivec2&)>());
}
SUBCASE("get_name") {
{
meta::member_index ivec2_x_index = ivec2_x.get_index();
CHECK(ivec2_x_index.get_name() == "x");
CHECK(std::move(ivec2_x_index).get_name() == "x");
}
{
meta::method_index ivec2_add_index = ivec2_add.get_index();
CHECK(ivec2_add_index.get_name() == "add");
CHECK(std::move(ivec2_add_index).get_name() == "add");
}
}
}

View File

@@ -35,6 +35,12 @@ TEST_CASE("meta/meta_states/ops") {
const meta::member ivec2_y = ivec2_type.get_member("y");
REQUIRE(ivec2_y);
SUBCASE("hash") {
CHECK(std::hash<meta::member>{}(ivec2_x) == std::hash<meta::member>{}(ivec2_x));
CHECK_FALSE(std::hash<meta::member>{}(ivec2_x) == std::hash<meta::member>{}({}));
CHECK_FALSE(std::hash<meta::member>{}(ivec2_x) == std::hash<meta::member>{}(ivec2_y));
}
SUBCASE("operator<") {
{
CHECK(meta::member{} < ivec2_x);

View File

@@ -45,6 +45,15 @@ TEST_CASE("meta/meta_types/ops") {
const meta::method ivec2_add = ivec2_type.get_method("add");
REQUIRE(ivec2_add);
SUBCASE("hash") {
const meta::member_type ivec2_x_type = ivec2_x.get_type();
const meta::method_type ivec2_add_type = ivec2_add.get_type();
CHECK(std::hash<meta::member_type>{}(ivec2_x_type) == std::hash<meta::member_type>{}(ivec2_x_type));
CHECK_FALSE(std::hash<meta::member_type>{}(ivec2_x_type) == std::hash<meta::member_type>{}({}));
CHECK_FALSE(std::hash<meta::member_type>{}(ivec2_x_type) == std::hash<meta::method_type>{}(ivec2_add_type));
}
SUBCASE("operator<") {
{
CHECK(ivec2_x.get_type() == ivec2_y.get_type());

View File

@@ -178,7 +178,7 @@ TEST_CASE("meta/meta_utilities/value") {
CHECK_THROWS(std::ignore = std::move(std::as_const(val)).get_as<int>());
}
CHECK(meta::uvalue{}.get_type() == meta::resolve_type<void>());
CHECK_FALSE(meta::uvalue{}.get_type());
}
SUBCASE("ivec2&") {

View File

@@ -14,6 +14,7 @@ Diagnostics:
- bugprone-easily-swappable-parameters
- bugprone-macro-parentheses
- cppcoreguidelines-macro-usage
- cppcoreguidelines-non-private-member-variables-in-classes
- misc-no-recursion
- misc-non-private-member-variables-in-classes
- misc-unused-using-decls

View File

@@ -33,6 +33,9 @@
#include "meta_indices/scope_index.hpp"
#include "meta_indices/variable_index.hpp"
#include "meta_invoke.hpp"
#include "meta_invoke/invoke.hpp"
#include "meta_registry.hpp"
#include "meta_states.hpp"
@@ -63,5 +66,4 @@
#include "meta_types/void_type.hpp"
#include "meta_uvalue.hpp"
#include "meta_uvalue/invoke.hpp"
#include "meta_uvalue/uvalue.hpp"

View File

@@ -20,6 +20,7 @@
#include "meta_base/is_in_place_type.hpp"
#include "meta_base/memory_buffer.hpp"
#include "meta_base/noncopyable.hpp"
#include "meta_base/nonesuch.hpp"
#include "meta_base/overloaded.hpp"
#include "meta_base/select_overload.hpp"
#include "meta_base/to_underlying.hpp"

View File

@@ -14,7 +14,6 @@
# define META_HPP_NO_RTTI
#endif
#include <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
@@ -49,3 +48,8 @@
# include <typeindex>
# include <typeinfo>
#endif
#if !defined(META_HPP_ASSERT)
# include <cassert>
# define META_HPP_ASSERT(...) assert(__VA_ARGS__) // NOLINT
#endif

View File

@@ -10,16 +10,23 @@
#if !defined(META_HPP_NO_EXCEPTIONS)
# define META_HPP_TRY try
# define META_HPP_CATCH(e) catch ( e )
# define META_HPP_CATCH(...) catch ( __VA_ARGS__ )
# define META_HPP_RETHROW() throw
# define META_HPP_THROW_AS(e, m) throw e(m)
# define META_HPP_THROW(...) throw ::meta_hpp::detail::exception(__VA_ARGS__)
#else
# define META_HPP_TRY if ( true )
# define META_HPP_CATCH(e) if ( false )
# define META_HPP_RETHROW() std::abort()
# define META_HPP_THROW_AS(e, m) std::terminate()
# define META_HPP_CATCH(...) if ( false )
# define META_HPP_RETHROW() std::terminate()
# define META_HPP_THROW(...) std::terminate()
#endif
#define META_HPP_THROW_IF(yesno, ...) \
do { \
if ( yesno ) { \
META_HPP_THROW(__VA_ARGS__); \
} \
} while ( false )
namespace meta_hpp::detail
{
#if !defined(META_HPP_NO_EXCEPTIONS)

View File

@@ -7,6 +7,7 @@
#pragma once
#include "base.hpp"
#include "exceptions.hpp"
namespace meta_hpp::detail
{
@@ -63,7 +64,7 @@ namespace meta_hpp::detail
}
R operator()(Args... args) const {
assert(vtable_ && "bad function call"); // NOLINT
META_HPP_THROW_IF(!vtable_, "bad function call");
return vtable_->call(*this, std::forward<Args>(args)...);
}
@@ -120,14 +121,15 @@ namespace meta_hpp::detail
static vtable_t table{
.call{[](const fixed_function& self, Args... args) -> R {
assert(self); // NOLINT
META_HPP_ASSERT(self);
const Fp& src = *buffer_cast<Fp>(self.buffer_);
return std::invoke(src, std::forward<Args>(args)...);
}},
.move{[](fixed_function& from, fixed_function& to) noexcept {
assert(from && !to); // NOLINT
META_HPP_ASSERT(!to);
META_HPP_ASSERT(from);
Fp& src = *buffer_cast<Fp>(from.buffer_);
std::construct_at(buffer_cast<Fp>(to.buffer_), std::move(src));
@@ -138,7 +140,7 @@ namespace meta_hpp::detail
}},
.destroy{[](fixed_function& self) {
assert(self); // NOLINT
META_HPP_ASSERT(self);
Fp& src = *buffer_cast<Fp>(self.buffer_);
std::destroy_at(&src);
@@ -151,7 +153,7 @@ namespace meta_hpp::detail
template < typename F, typename Fp = std::decay_t<F> >
static void construct(fixed_function& dst, F&& fun) {
assert(!dst); // NOLINT
META_HPP_ASSERT(!dst);
static_assert(sizeof(Fp) <= sizeof(buffer_t));
static_assert(alignof(buffer_t) % alignof(Fp) == 0);

View File

@@ -0,0 +1,22 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "base.hpp"
namespace meta_hpp::detail
{
class nonesuch {
public:
nonesuch() = delete;
~nonesuch() = delete;
nonesuch(nonesuch&&) = delete;
nonesuch(const nonesuch&) = delete;
nonesuch& operator=(nonesuch&&) = delete;
nonesuch& operator=(const nonesuch&) = delete;
};
}

View File

@@ -20,13 +20,13 @@ namespace meta_hpp::detail
concept enum_kind = std::is_enum_v<T>;
template < typename T >
concept function_kind = (std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t<T>>);
concept function_pointer_kind = (std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t<T>>);
template < typename T >
concept member_kind = std::is_member_object_pointer_v<T>;
concept member_pointer_kind = std::is_member_object_pointer_v<T>;
template < typename T >
concept method_kind = std::is_member_function_pointer_v<T>;
concept method_pointer_kind = std::is_member_function_pointer_v<T>;
template < typename T >
concept nullptr_kind = std::is_null_pointer_v<T>;
@@ -68,9 +68,9 @@ namespace meta_hpp::detail
if constexpr ( array_kind<T> ) { return type_kind::array_; }
if constexpr ( class_kind<T> ) { return type_kind::class_; }
if constexpr ( enum_kind<T> ) { return type_kind::enum_; }
if constexpr ( function_kind<T> ) { return type_kind::function_; }
if constexpr ( member_kind<T> ) { return type_kind::member_; }
if constexpr ( method_kind<T> ) { return type_kind::method_; }
if constexpr ( function_pointer_kind<T> ) { return type_kind::function_; }
if constexpr ( member_pointer_kind<T> ) { return type_kind::member_; }
if constexpr ( method_pointer_kind<T> ) { return type_kind::method_; }
if constexpr ( nullptr_kind<T> ) { return type_kind::nullptr_; }
if constexpr ( number_kind<T> ) { return type_kind::number_; }
if constexpr ( pointer_kind<T> ) { return type_kind::pointer_; }

View File

@@ -28,12 +28,12 @@ namespace meta_hpp::detail
template < typename Class, typename Member >
concept class_bind_member_kind //
= class_kind<Class> && member_kind<Member> //
= class_kind<Class> && member_pointer_kind<Member> //
&& std::is_same_v<Class, typename member_traits<Member>::class_type>; //
template < typename Class, typename Method >
concept class_bind_method_kind //
= class_kind<Class> && method_kind<Method> //
= class_kind<Class> && method_pointer_kind<Method> //
&& std::is_same_v<Class, typename method_traits<Method>::class_type>; //
}
@@ -93,7 +93,7 @@ namespace meta_hpp
}
protected:
using data_ptr = typename Type::data_ptr;
using data_ptr = typename detail::type_traits<Type>::data_ptr;
using data_ref = decltype(*std::declval<data_ptr>());
[[nodiscard]] data_ref get_data() noexcept {
@@ -118,7 +118,7 @@ namespace meta_hpp
}
protected:
using state_ptr = typename State::state_ptr;
using state_ptr = typename detail::state_traits<State>::state_ptr;
using state_ref = decltype(*std::declval<state_ptr>());
[[nodiscard]] state_ref get_state() noexcept {
@@ -173,38 +173,38 @@ namespace meta_hpp
// function_
template < detail::function_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
class_bind& function_(std::string name, Function function, Policy = {});
template < detail::function_pointer_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
class_bind& function_(std::string name, Function function_ptr, Policy = {});
template < detail::function_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
class_bind& function_(std::string name, Function function, function_opts opts, Policy = {});
template < detail::function_pointer_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
class_bind& function_(std::string name, Function function_ptr, function_opts opts, Policy = {});
template < detail::function_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
class_bind& function_(std::string name, Function function, string_ilist arguments, Policy = {});
template < detail::function_pointer_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
class_bind& function_(std::string name, Function function_ptr, string_ilist arguments, Policy = {});
// member_
template < detail::member_kind Member, member_policy_kind Policy = member_policy::as_copy_t >
template < detail::member_pointer_kind Member, member_policy_kind Policy = member_policy::as_copy_t >
requires detail::class_bind_member_kind<Class, Member>
class_bind& member_(std::string name, Member member, Policy = {});
class_bind& member_(std::string name, Member member_ptr, Policy = {});
template < detail::member_kind Member, member_policy_kind Policy = member_policy::as_copy_t >
template < detail::member_pointer_kind Member, member_policy_kind Policy = member_policy::as_copy_t >
requires detail::class_bind_member_kind<Class, Member>
class_bind& member_(std::string name, Member member, member_opts opts, Policy = {});
class_bind& member_(std::string name, Member member_ptr, member_opts opts, Policy = {});
// method_
template < detail::method_kind Method, method_policy_kind Policy = method_policy::as_copy_t >
template < detail::method_pointer_kind Method, method_policy_kind Policy = method_policy::as_copy_t >
requires detail::class_bind_method_kind<Class, Method>
class_bind& method_(std::string name, Method method, Policy = {});
class_bind& method_(std::string name, Method method_ptr, Policy = {});
template < detail::method_kind Method, method_policy_kind Policy = method_policy::as_copy_t >
template < detail::method_pointer_kind Method, method_policy_kind Policy = method_policy::as_copy_t >
requires detail::class_bind_method_kind<Class, Method>
class_bind& method_(std::string name, Method method, method_opts opts, Policy = {});
class_bind& method_(std::string name, Method method_ptr, method_opts opts, Policy = {});
template < detail::method_kind Method, method_policy_kind Policy = method_policy::as_copy_t >
template < detail::method_pointer_kind Method, method_policy_kind Policy = method_policy::as_copy_t >
requires detail::class_bind_method_kind<Class, Method>
class_bind& method_(std::string name, Method method, string_ilist arguments, Policy = {});
class_bind& method_(std::string name, Method method_ptr, string_ilist arguments, Policy = {});
// typdef_
@@ -214,10 +214,10 @@ namespace meta_hpp
// variable_
template < detail::pointer_kind Pointer, variable_policy_kind Policy = variable_policy::as_copy_t >
class_bind& variable_(std::string name, Pointer pointer, Policy = {});
class_bind& variable_(std::string name, Pointer variable_ptr, Policy = {});
template < detail::pointer_kind Pointer, variable_policy_kind Policy = variable_policy::as_copy_t >
class_bind& variable_(std::string name, Pointer pointer, variable_opts opts, Policy = {});
class_bind& variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy = {});
};
}
@@ -235,7 +235,7 @@ namespace meta_hpp
namespace meta_hpp
{
template < detail::function_kind Function >
template < detail::function_pointer_kind Function >
class function_bind final : public type_bind_base<function_type> {
public:
explicit function_bind(metadata_map metadata);
@@ -244,7 +244,7 @@ namespace meta_hpp
namespace meta_hpp
{
template < detail::member_kind Member >
template < detail::member_pointer_kind Member >
class member_bind final : public type_bind_base<member_type> {
public:
explicit member_bind(metadata_map metadata);
@@ -253,7 +253,7 @@ namespace meta_hpp
namespace meta_hpp
{
template < detail::method_kind Method >
template < detail::method_pointer_kind Method >
class method_bind final : public type_bind_base<method_type> {
public:
explicit method_bind(metadata_map metadata);
@@ -313,14 +313,14 @@ namespace meta_hpp
// function_
template < detail::function_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
scope_bind& function_(std::string name, Function function, Policy = {});
template < detail::function_pointer_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
scope_bind& function_(std::string name, Function function_ptr, Policy = {});
template < detail::function_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
scope_bind& function_(std::string name, Function function, function_opts opts, Policy = {});
template < detail::function_pointer_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
scope_bind& function_(std::string name, Function function_ptr, function_opts opts, Policy = {});
template < detail::function_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
scope_bind& function_(std::string name, Function function, string_ilist arguments, Policy = {});
template < detail::function_pointer_kind Function, function_policy_kind Policy = function_policy::as_copy_t >
scope_bind& function_(std::string name, Function function_ptr, string_ilist arguments, Policy = {});
// typedef_
@@ -330,10 +330,10 @@ namespace meta_hpp
// variable_
template < detail::pointer_kind Pointer, variable_policy_kind Policy = variable_policy::as_copy_t >
scope_bind& variable_(std::string name, Pointer pointer, Policy = {});
scope_bind& variable_(std::string name, Pointer variable_ptr, Policy = {});
template < detail::pointer_kind Pointer, variable_policy_kind Policy = variable_policy::as_copy_t >
scope_bind& variable_(std::string name, Pointer pointer, variable_opts opts, Policy = {});
scope_bind& variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy = {});
};
}
@@ -354,17 +354,17 @@ namespace meta_hpp
return enum_bind<Enum>{std::move(metadata)};
}
template < detail::function_kind Function >
template < detail::function_pointer_kind Function >
function_bind<Function> function_(metadata_map metadata = {}) {
return function_bind<Function>{std::move(metadata)};
}
template < detail::member_kind Member >
template < detail::member_pointer_kind Member >
member_bind<Member> member_(metadata_map metadata = {}) {
return member_bind<Member>{std::move(metadata)};
}
template < detail::method_kind Method >
template < detail::method_pointer_kind Method >
method_bind<Method> method_(metadata_map metadata = {}) {
return method_bind<Method>{std::move(metadata)};
}

View File

@@ -72,9 +72,10 @@ namespace meta_hpp
{
auto state = detail::constructor_state::make<Policy, Class, Args...>(std::move(opts.metadata));
if ( opts.arguments.size() > state->arguments.size() ) {
META_HPP_THROW_AS(exception, "provided argument names don't match constructor argument count");
}
META_HPP_THROW_IF( //
opts.arguments.size() > state->arguments.size(),
"provided argument names don't match constructor argument count"
);
for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) {
argument& arg = state->arguments[i];
@@ -82,7 +83,7 @@ namespace meta_hpp
detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata);
}
detail::insert_or_assign(get_data().constructors, std::move(state));
detail::insert_or_assign(get_data().constructors, constructor{std::move(state)});
return *this;
}
@@ -102,7 +103,7 @@ namespace meta_hpp
requires detail::class_bind_destructor_kind<Class>
{
auto state = detail::destructor_state::make<Class>(std::move(opts.metadata));
detail::insert_or_assign(get_data().destructors, std::move(state));
detail::insert_or_assign(get_data().destructors, destructor{std::move(state)});
return *this;
}
@@ -111,19 +112,20 @@ namespace meta_hpp
//
template < detail::class_kind Class >
template < detail::function_kind Function, function_policy_kind Policy >
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function, Policy policy) {
return function_(std::move(name), std::move(function), {}, policy);
template < detail::function_pointer_kind Function, function_policy_kind Policy >
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function_ptr, Policy policy) {
return function_(std::move(name), function_ptr, {}, policy);
}
template < detail::class_kind Class >
template < detail::function_kind Function, function_policy_kind Policy >
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function, function_opts opts, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), std::move(function), std::move(opts.metadata));
template < detail::function_pointer_kind Function, function_policy_kind Policy >
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function_ptr, function_opts opts, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), function_ptr, std::move(opts.metadata));
if ( opts.arguments.size() > state->arguments.size() ) {
META_HPP_THROW_AS(exception, "provided arguments don't match function argument count");
}
META_HPP_THROW_IF( //
opts.arguments.size() > state->arguments.size(),
"provided arguments don't match function argument count"
);
for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) {
argument& arg = state->arguments[i];
@@ -131,18 +133,19 @@ namespace meta_hpp
detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata);
}
detail::insert_or_assign(get_data().functions, std::move(state));
detail::insert_or_assign(get_data().functions, function{std::move(state)});
return *this;
}
template < detail::class_kind Class >
template < detail::function_kind Function, function_policy_kind Policy >
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function, string_ilist arguments, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), std::move(function), {});
template < detail::function_pointer_kind Function, function_policy_kind Policy >
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), function_ptr, {});
if ( arguments.size() > state->arguments.size() ) {
META_HPP_THROW_AS(exception, "provided argument names don't match function argument count");
}
META_HPP_THROW_IF( //
arguments.size() > state->arguments.size(),
"provided argument names don't match function argument count"
);
for ( std::size_t i = 0; i < arguments.size(); ++i ) {
argument& arg = state->arguments[i];
@@ -150,7 +153,7 @@ namespace meta_hpp
detail::state_access(arg)->name = std::data(arguments)[i];
}
detail::insert_or_assign(get_data().functions, std::move(state));
detail::insert_or_assign(get_data().functions, function{std::move(state)});
return *this;
}
@@ -159,18 +162,18 @@ namespace meta_hpp
//
template < detail::class_kind Class >
template < detail::member_kind Member, member_policy_kind Policy >
template < detail::member_pointer_kind Member, member_policy_kind Policy >
requires detail::class_bind_member_kind<Class, Member>
class_bind<Class>& class_bind<Class>::member_(std::string name, Member member, Policy policy) {
return member_(std::move(name), std::move(member), {}, policy);
class_bind<Class>& class_bind<Class>::member_(std::string name, Member member_ptr, Policy policy) {
return member_(std::move(name), member_ptr, {}, policy);
}
template < detail::class_kind Class >
template < detail::member_kind Member, member_policy_kind Policy >
template < detail::member_pointer_kind Member, member_policy_kind Policy >
requires detail::class_bind_member_kind<Class, Member>
class_bind<Class>& class_bind<Class>::member_(std::string name, Member member, member_opts opts, Policy) {
auto state = detail::member_state::make<Policy>(std::move(name), std::move(member), std::move(opts.metadata));
detail::insert_or_assign(get_data().members, std::move(state));
class_bind<Class>& class_bind<Class>::member_(std::string name, Member member_ptr, member_opts opts, Policy) {
auto state = detail::member_state::make<Policy>(std::move(name), member_ptr, std::move(opts.metadata));
detail::insert_or_assign(get_data().members, member{std::move(state)});
return *this;
}
@@ -179,21 +182,22 @@ namespace meta_hpp
//
template < detail::class_kind Class >
template < detail::method_kind Method, method_policy_kind Policy >
template < detail::method_pointer_kind Method, method_policy_kind Policy >
requires detail::class_bind_method_kind<Class, Method>
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method, Policy policy) {
return method_(std::move(name), std::move(method), {}, policy);
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method_ptr, Policy policy) {
return method_(std::move(name), method_ptr, {}, policy);
}
template < detail::class_kind Class >
template < detail::method_kind Method, method_policy_kind Policy >
template < detail::method_pointer_kind Method, method_policy_kind Policy >
requires detail::class_bind_method_kind<Class, Method>
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method, method_opts opts, Policy) {
auto state = detail::method_state::make<Policy>(std::move(name), std::move(method), std::move(opts.metadata));
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method_ptr, method_opts opts, Policy) {
auto state = detail::method_state::make<Policy>(std::move(name), method_ptr, std::move(opts.metadata));
if ( opts.arguments.size() > state->arguments.size() ) {
META_HPP_THROW_AS(exception, "provided arguments don't match method argument count");
}
META_HPP_THROW_IF( //
opts.arguments.size() > state->arguments.size(),
"provided arguments don't match method argument count"
);
for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) {
argument& arg = state->arguments[i];
@@ -201,19 +205,20 @@ namespace meta_hpp
detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata);
}
detail::insert_or_assign(get_data().methods, std::move(state));
detail::insert_or_assign(get_data().methods, method{std::move(state)});
return *this;
}
template < detail::class_kind Class >
template < detail::method_kind Method, method_policy_kind Policy >
template < detail::method_pointer_kind Method, method_policy_kind Policy >
requires detail::class_bind_method_kind<Class, Method>
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method, string_ilist arguments, Policy) {
auto state = detail::method_state::make<Policy>(std::move(name), std::move(method), {});
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method_ptr, string_ilist arguments, Policy) {
auto state = detail::method_state::make<Policy>(std::move(name), method_ptr, {});
if ( arguments.size() > state->arguments.size() ) {
META_HPP_THROW_AS(exception, "provided argument names don't match method argument count");
}
META_HPP_THROW_IF( //
arguments.size() > state->arguments.size(),
"provided argument names don't match method argument count"
);
for ( std::size_t i = 0; i < arguments.size(); ++i ) {
argument& arg = state->arguments[i];
@@ -221,7 +226,7 @@ namespace meta_hpp
detail::state_access(arg)->name = std::data(arguments)[i];
}
detail::insert_or_assign(get_data().methods, std::move(state));
detail::insert_or_assign(get_data().methods, method{std::move(state)});
return *this;
}
@@ -242,15 +247,15 @@ namespace meta_hpp
template < detail::class_kind Class >
template < detail::pointer_kind Pointer, variable_policy_kind Policy >
class_bind<Class>& class_bind<Class>::variable_(std::string name, Pointer pointer, Policy policy) {
return variable_(std::move(name), std::move(pointer), {}, policy);
class_bind<Class>& class_bind<Class>::variable_(std::string name, Pointer variable_ptr, Policy policy) {
return variable_(std::move(name), variable_ptr, {}, policy);
}
template < detail::class_kind Class >
template < detail::pointer_kind Pointer, variable_policy_kind Policy >
class_bind<Class>& class_bind<Class>::variable_(std::string name, Pointer pointer, variable_opts opts, Policy) {
auto state = detail::variable_state::make<Policy>(std::move(name), std::move(pointer), std::move(opts.metadata));
detail::insert_or_assign(get_data().variables, std::move(state));
class_bind<Class>& class_bind<Class>::variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy) {
auto state = detail::variable_state::make<Policy>(std::move(name), variable_ptr, std::move(opts.metadata));
detail::insert_or_assign(get_data().variables, variable{std::move(state)});
return *this;
}
}

View File

@@ -24,7 +24,7 @@ namespace meta_hpp
template < detail::enum_kind Enum >
enum_bind<Enum>& enum_bind<Enum>::evalue_(std::string name, Enum value, evalue_opts opts) {
auto state = detail::evalue_state::make(std::move(name), std::move(value), std::move(opts.metadata));
detail::insert_or_assign(get_data().evalues, std::move(state));
detail::insert_or_assign(get_data().evalues, evalue{std::move(state)});
return *this;
}
}

View File

@@ -12,7 +12,7 @@
namespace meta_hpp
{
template < detail::function_kind Function >
template < detail::function_pointer_kind Function >
function_bind<Function>::function_bind(metadata_map metadata)
: type_bind_base{resolve_type<Function>(), std::move(metadata)} {}
}

View File

@@ -12,7 +12,7 @@
namespace meta_hpp
{
template < detail::member_kind Member >
template < detail::member_pointer_kind Member >
member_bind<Member>::member_bind(metadata_map metadata)
: type_bind_base{resolve_type<Member>(), std::move(metadata)} {}
}

View File

@@ -12,7 +12,7 @@
namespace meta_hpp
{
template < detail::method_kind Method >
template < detail::method_pointer_kind Method >
method_bind<Method>::method_bind(metadata_map metadata)
: type_bind_base{resolve_type<Method>(), std::move(metadata)} {}
}

View File

@@ -19,18 +19,19 @@ namespace meta_hpp
// function_
//
template < detail::function_kind Function, function_policy_kind Policy >
scope_bind& scope_bind::function_(std::string name, Function function, Policy policy) {
return function_(std::move(name), std::move(function), {}, policy);
template < detail::function_pointer_kind Function, function_policy_kind Policy >
scope_bind& scope_bind::function_(std::string name, Function function_ptr, Policy policy) {
return function_(std::move(name), function_ptr, {}, policy);
}
template < detail::function_kind Function, function_policy_kind Policy >
scope_bind& scope_bind::function_(std::string name, Function function, function_opts opts, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), std::move(function), std::move(opts.metadata));
template < detail::function_pointer_kind Function, function_policy_kind Policy >
scope_bind& scope_bind::function_(std::string name, Function function_ptr, function_opts opts, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), function_ptr, std::move(opts.metadata));
if ( opts.arguments.size() > state->arguments.size() ) {
META_HPP_THROW_AS(exception, "provided arguments don't match function argument count");
}
META_HPP_THROW_IF( //
opts.arguments.size() > state->arguments.size(),
"provided arguments don't match function argument count"
);
for ( std::size_t i = 0; i < opts.arguments.size(); ++i ) {
argument& arg = state->arguments[i];
@@ -38,17 +39,18 @@ namespace meta_hpp
detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata);
}
detail::insert_or_assign(get_state().functions, std::move(state));
detail::insert_or_assign(get_state().functions, function{std::move(state)});
return *this;
}
template < detail::function_kind Function, function_policy_kind Policy >
scope_bind& scope_bind::function_(std::string name, Function function, string_ilist arguments, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), std::move(function), {});
template < detail::function_pointer_kind Function, function_policy_kind Policy >
scope_bind& scope_bind::function_(std::string name, Function function_ptr, string_ilist arguments, Policy) {
auto state = detail::function_state::make<Policy>(std::move(name), function_ptr, {});
if ( arguments.size() > state->arguments.size() ) {
META_HPP_THROW_AS(exception, "provided argument names don't match function argument count");
}
META_HPP_THROW_IF( //
arguments.size() > state->arguments.size(),
"provided argument names don't match function argument count"
);
for ( std::size_t i = 0; i < arguments.size(); ++i ) {
argument& arg = state->arguments[i];
@@ -56,7 +58,7 @@ namespace meta_hpp
detail::state_access(arg)->name = std::data(arguments)[i];
}
detail::insert_or_assign(get_state().functions, std::move(state));
detail::insert_or_assign(get_state().functions, function{std::move(state)});
return *this;
}
@@ -75,14 +77,14 @@ namespace meta_hpp
//
template < detail::pointer_kind Pointer, variable_policy_kind Policy >
scope_bind& scope_bind::variable_(std::string name, Pointer pointer, Policy policy) {
return variable_(std::move(name), std::move(pointer), {}, policy);
scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, Policy policy) {
return variable_(std::move(name), variable_ptr, {}, policy);
}
template < detail::pointer_kind Pointer, variable_policy_kind Policy >
scope_bind& scope_bind::variable_(std::string name, Pointer pointer, variable_opts opts, Policy) {
auto state = detail::variable_state::make<Policy>(std::move(name), std::move(pointer), std::move(opts.metadata));
detail::insert_or_assign(get_state().variables, std::move(state));
scope_bind& scope_bind::variable_(std::string name, Pointer variable_ptr, variable_opts opts, Policy) {
auto state = detail::variable_state::make<Policy>(std::move(name), variable_ptr, std::move(opts.metadata));
detail::insert_or_assign(get_state().variables, variable{std::move(state)});
return *this;
}
}

View File

@@ -22,8 +22,68 @@ namespace meta_hpp::detail
|| std::is_same_v<T, scope> //
|| std::is_same_v<T, variable>; //
template < state_family T >
[[nodiscard]] typename T::state_ptr state_access(const T& state) {
template < state_family State >
struct state_traits;
template < state_family State >
[[nodiscard]] typename state_traits<State>::state_ptr state_access(const State& state) {
return state.state_;
}
}
namespace meta_hpp::detail
{
template <>
struct state_traits<argument> {
using index_type = argument_index;
using state_ptr = argument_state_ptr;
};
template <>
struct state_traits<constructor> {
using index_type = constructor_index;
using state_ptr = constructor_state_ptr;
};
template <>
struct state_traits<destructor> {
using index_type = destructor_index;
using state_ptr = destructor_state_ptr;
};
template <>
struct state_traits<evalue> {
using index_type = evalue_index;
using state_ptr = evalue_state_ptr;
};
template <>
struct state_traits<function> {
using index_type = function_index;
using state_ptr = function_state_ptr;
};
template <>
struct state_traits<member> {
using index_type = member_index;
using state_ptr = member_state_ptr;
};
template <>
struct state_traits<method> {
using index_type = method_index;
using state_ptr = method_state_ptr;
};
template <>
struct state_traits<scope> {
using index_type = scope_index;
using state_ptr = scope_state_ptr;
};
template <>
struct state_traits<variable> {
using index_type = variable_index;
using state_ptr = variable_state_ptr;
};
}

View File

@@ -8,6 +8,18 @@
#include "../meta_base.hpp"
#include "type_traits/array_traits.hpp"
#include "type_traits/class_traits.hpp"
#include "type_traits/constructor_traits.hpp"
#include "type_traits/destructor_traits.hpp"
#include "type_traits/enum_traits.hpp"
#include "type_traits/function_traits.hpp"
#include "type_traits/member_traits.hpp"
#include "type_traits/method_traits.hpp"
#include "type_traits/number_traits.hpp"
#include "type_traits/pointer_traits.hpp"
#include "type_traits/reference_traits.hpp"
namespace meta_hpp::detail
{
template < typename T >
@@ -27,8 +39,97 @@ namespace meta_hpp::detail
|| std::is_same_v<T, reference_type> //
|| std::is_same_v<T, void_type>; //
template < type_family T >
[[nodiscard]] typename T::data_ptr type_access(const T& type) {
template <type_family Type>
struct type_traits;
template < type_family Type >
[[nodiscard]] typename type_traits<Type>::data_ptr type_access(const Type& type) {
return type.data_;
}
}
namespace meta_hpp::detail
{
template <>
struct type_traits<any_type> {
using data_ptr = type_data_base*;
};
template <>
struct type_traits<array_type> {
using data_ptr = array_type_data*;
inline static constexpr type_kind kind{type_kind::array_};
};
template <>
struct type_traits<class_type> {
using data_ptr = class_type_data*;
inline static constexpr type_kind kind{type_kind::class_};
};
template <>
struct type_traits<constructor_type> {
using data_ptr = constructor_type_data*;
inline static constexpr type_kind kind{type_kind::constructor_};
};
template <>
struct type_traits<destructor_type> {
using data_ptr = destructor_type_data*;
inline static constexpr type_kind kind{type_kind::destructor_};
};
template <>
struct type_traits<enum_type> {
using data_ptr = enum_type_data*;
inline static constexpr type_kind kind{type_kind::enum_};
};
template <>
struct type_traits<function_type> {
using data_ptr = function_type_data*;
inline static constexpr type_kind kind{type_kind::function_};
};
template <>
struct type_traits<member_type> {
using data_ptr = member_type_data*;
inline static constexpr type_kind kind{type_kind::member_};
};
template <>
struct type_traits<method_type> {
using data_ptr = method_type_data*;
inline static constexpr type_kind kind{type_kind::method_};
};
template <>
struct type_traits<nullptr_type> {
using data_ptr = nullptr_type_data*;
inline static constexpr type_kind kind{type_kind::nullptr_};
};
template <>
struct type_traits<number_type> {
using data_ptr = number_type_data*;
inline static constexpr type_kind kind{type_kind::number_};
};
template <>
struct type_traits<pointer_type> {
using data_ptr = pointer_type_data*;
inline static constexpr type_kind kind{type_kind::pointer_};
};
template <>
struct type_traits<reference_type> {
using data_ptr = reference_type_data*;
inline static constexpr type_kind kind{type_kind::reference_};
};
template <>
struct type_traits<void_type> {
using data_ptr = void_type_data*;
inline static constexpr type_kind kind{type_kind::void_};
};
}

View File

@@ -83,17 +83,17 @@ namespace meta_hpp::detail
return resolve_enum_type<Enum>();
}
template < function_kind Function >
template < function_pointer_kind Function >
[[nodiscard]] function_type resolve_type() {
return resolve_function_type<Function>();
}
template < member_kind Member >
template < member_pointer_kind Member >
[[nodiscard]] member_type resolve_type() {
return resolve_member_type<Member>();
}
template < method_kind Method >
template < method_pointer_kind Method >
[[nodiscard]] method_type resolve_type() {
return resolve_method_type<Method>();
}
@@ -149,17 +149,17 @@ namespace meta_hpp::detail
return enum_type{resolve_enum_type_data<Enum>()};
}
template < function_kind Function >
template < function_pointer_kind Function >
[[nodiscard]] function_type resolve_function_type() {
return function_type{resolve_function_type_data<Function>()};
}
template < member_kind Member >
template < member_pointer_kind Member >
[[nodiscard]] member_type resolve_member_type() {
return member_type{resolve_member_type_data<Member>()};
}
template < method_kind Method >
template < method_pointer_kind Method >
[[nodiscard]] method_type resolve_method_type() {
return method_type{resolve_method_type_data<Method>()};
}
@@ -220,19 +220,19 @@ namespace meta_hpp::detail
return &data;
}
template < function_kind Function >
template < function_pointer_kind Function >
[[nodiscard]] function_type_data* resolve_function_type_data() {
static function_type_data data = (ensure_type<Function>(data), function_type_data{type_list<Function>{}});
return &data;
}
template < member_kind Member >
template < member_pointer_kind Member >
[[nodiscard]] member_type_data* resolve_member_type_data() {
static member_type_data data = (ensure_type<Member>(data), member_type_data{type_list<Member>{}});
return &data;
}
template < method_kind Method >
template < method_pointer_kind Method >
[[nodiscard]] method_type_data* resolve_method_type_data() {
static method_type_data data = (ensure_type<Method>(data), method_type_data{type_list<Method>{}});
return &data;

View File

@@ -20,7 +20,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < function_kind Function >
template < function_pointer_kind Function >
struct function_traits;
template < typename R, typename... Args >

View File

@@ -20,7 +20,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < member_kind Member >
template < member_pointer_kind Member >
struct member_traits;
template < typename V, typename C >

View File

@@ -23,7 +23,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < method_kind Method >
template < method_pointer_kind Method >
struct method_traits;
template < typename R, typename C, typename... Args >

View File

@@ -77,7 +77,7 @@ namespace meta_hpp::detail
return ref_type_;
}
[[nodiscard]] const any_type& get_raw_type() const noexcept {
[[nodiscard]] any_type get_raw_type() const noexcept {
return raw_type_;
}
@@ -234,9 +234,7 @@ namespace meta_hpp::detail
template < typename To >
// NOLINTNEXTLINE(*-cognitive-complexity)
To uarg::cast() const {
if ( !can_cast_to<To>() ) {
META_HPP_THROW_AS(exception, "bad argument cast");
}
META_HPP_THROW_IF(!can_cast_to<To>(), "bad argument cast");
using to_raw_type_cv = std::remove_reference_t<To>;
using to_raw_type = std::remove_cv_t<to_raw_type_cv>;
@@ -345,6 +343,6 @@ namespace meta_hpp::detail
}
}
META_HPP_THROW_AS(exception, "bad argument cast");
META_HPP_THROW("bad argument cast");
}
}

View File

@@ -82,7 +82,7 @@ namespace meta_hpp::detail
return ref_type_;
}
[[nodiscard]] const any_type& get_raw_type() const noexcept {
[[nodiscard]] any_type get_raw_type() const noexcept {
return raw_type_;
}
@@ -183,9 +183,7 @@ namespace meta_hpp::detail
{
template < inst_class_ref_kind Q >
decltype(auto) uinst::cast() const {
if ( !can_cast_to<Q>() ) {
META_HPP_THROW_AS(exception, "bad instance cast");
}
META_HPP_THROW_IF(!can_cast_to<Q>(), "bad instance cast");
using inst_class_cv = std::remove_reference_t<Q>;
using inst_class = std::remove_cv_t<inst_class_cv>;
@@ -233,6 +231,6 @@ namespace meta_hpp::detail
}
}
META_HPP_THROW_AS(exception, "bad instance cast");
META_HPP_THROW("bad instance cast");
}
}

View File

@@ -15,16 +15,16 @@ namespace meta_hpp
{
class argument_index final {
public:
[[nodiscard]] const any_type& get_type() const noexcept;
argument_index() = delete;
explicit argument_index(any_type type, std::size_t position);
[[nodiscard]] any_type get_type() const noexcept;
[[nodiscard]] std::size_t get_position() const noexcept;
void swap(argument_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const argument_index&) const = default;
private:
friend detail::argument_state;
explicit argument_index(any_type type, std::size_t position);
private:
any_type type_;
std::size_t position_{};
@@ -32,46 +32,48 @@ namespace meta_hpp
class constructor_index final {
public:
[[nodiscard]] const constructor_type& get_type() const noexcept;
constructor_index() = delete;
explicit constructor_index(constructor_type type);
[[nodiscard]] constructor_type get_type() const noexcept;
void swap(constructor_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const constructor_index&) const = default;
private:
friend detail::constructor_state;
explicit constructor_index(constructor_type type);
private:
constructor_type type_;
};
class destructor_index final {
public:
[[nodiscard]] const destructor_type& get_type() const noexcept;
destructor_index() = delete;
explicit destructor_index(destructor_type type);
[[nodiscard]] destructor_type get_type() const noexcept;
void swap(destructor_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const destructor_index&) const = default;
private:
friend detail::destructor_state;
explicit destructor_index(destructor_type type);
private:
destructor_type type_;
};
class evalue_index final {
public:
[[nodiscard]] const enum_type& get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
evalue_index() = delete;
explicit evalue_index(enum_type type, std::string name);
[[nodiscard]] enum_type get_type() const noexcept;
[[nodiscard]] std::string&& get_name() && noexcept;
[[nodiscard]] const std::string& get_name() const& noexcept;
void swap(evalue_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const evalue_index&) const = default;
private:
friend detail::evalue_state;
explicit evalue_index(enum_type type, std::string name);
private:
enum_type type_;
std::string name_;
@@ -79,16 +81,18 @@ namespace meta_hpp
class function_index final {
public:
[[nodiscard]] const function_type& get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
function_index() = delete;
explicit function_index(function_type type, std::string name);
[[nodiscard]] function_type get_type() const noexcept;
[[nodiscard]] std::string&& get_name() && noexcept;
[[nodiscard]] const std::string& get_name() const& noexcept;
void swap(function_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const function_index&) const = default;
private:
friend detail::function_state;
explicit function_index(function_type type, std::string name);
private:
function_type type_;
std::string name_;
@@ -96,16 +100,18 @@ namespace meta_hpp
class member_index final {
public:
[[nodiscard]] const member_type& get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
member_index() = delete;
explicit member_index(member_type type, std::string name);
[[nodiscard]] member_type get_type() const noexcept;
[[nodiscard]] std::string&& get_name() && noexcept;
[[nodiscard]] const std::string& get_name() const& noexcept;
void swap(member_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const member_index&) const = default;
private:
friend detail::member_state;
explicit member_index(member_type type, std::string name);
private:
member_type type_;
std::string name_;
@@ -113,16 +119,18 @@ namespace meta_hpp
class method_index final {
public:
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] const method_type& get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const method_index&) const = default;
private:
friend detail::method_state;
method_index() = delete;
explicit method_index(method_type type, std::string name);
[[nodiscard]] method_type get_type() const noexcept;
[[nodiscard]] std::string&& get_name() && noexcept;
[[nodiscard]] const std::string& get_name() const& noexcept;
void swap(method_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const method_index&) const = default;
private:
method_type type_;
std::string name_;
@@ -130,43 +138,51 @@ namespace meta_hpp
class scope_index final {
public:
[[nodiscard]] const std::string& get_name() const noexcept;
scope_index() = delete;
explicit scope_index(std::string name);
[[nodiscard]] std::string&& get_name() && noexcept;
[[nodiscard]] const std::string& get_name() const& noexcept;
void swap(scope_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const scope_index&) const = default;
private:
friend detail::scope_state;
explicit scope_index(std::string name);
private:
std::string name_;
};
class variable_index final {
public:
[[nodiscard]] const pointer_type& get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
variable_index() = delete;
explicit variable_index(pointer_type type, std::string name);
[[nodiscard]] pointer_type get_type() const noexcept;
[[nodiscard]] std::string&& get_name() && noexcept;
[[nodiscard]] const std::string& get_name() const& noexcept;
void swap(variable_index& other) noexcept;
[[nodiscard]] std::size_t get_hash() const noexcept;
[[nodiscard]] std::strong_ordering operator<=>(const variable_index&) const = default;
private:
friend detail::variable_state;
explicit variable_index(pointer_type type, std::string name);
private:
pointer_type type_;
std::string name_;
};
template < detail::index_family Index >
void swap(Index& l, Index& r) noexcept {
l.swap(r);
}
}
namespace std
{
template < meta_hpp::detail::index_family T >
struct hash<T> {
size_t operator()(const T& t) const noexcept {
return t.get_hash();
template < meta_hpp::detail::index_family Index >
struct hash<Index> {
size_t operator()(const Index& index) const noexcept {
return index.get_hash();
}
};
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -17,7 +16,7 @@ namespace meta_hpp
: type_{type}
, position_{position} {}
inline const any_type& argument_index::get_type() const noexcept {
inline any_type argument_index::get_type() const noexcept {
return type_;
}
@@ -25,6 +24,11 @@ namespace meta_hpp
return position_;
}
inline void argument_index::swap(argument_index& other) noexcept {
std::swap(type_, other.type_);
std::swap(position_, other.position_);
}
inline std::size_t argument_index::get_hash() const noexcept {
return detail::hash_combiner{}(detail::hash_combiner{}(type_), position_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -16,10 +15,14 @@ namespace meta_hpp
inline constructor_index::constructor_index(constructor_type type)
: type_{type} {}
inline const constructor_type& constructor_index::get_type() const noexcept {
inline constructor_type constructor_index::get_type() const noexcept {
return type_;
}
inline void constructor_index::swap(constructor_index& other) noexcept {
std::swap(type_, other.type_);
}
inline std::size_t constructor_index::get_hash() const noexcept {
return detail::hash_combiner{}(type_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -16,10 +15,14 @@ namespace meta_hpp
inline destructor_index::destructor_index(destructor_type type)
: type_{type} {}
inline const destructor_type& destructor_index::get_type() const noexcept {
inline destructor_type destructor_index::get_type() const noexcept {
return type_;
}
inline void destructor_index::swap(destructor_index& other) noexcept {
std::swap(type_, other.type_);
}
inline std::size_t destructor_index::get_hash() const noexcept {
return detail::hash_combiner{}(type_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -17,14 +16,23 @@ namespace meta_hpp
: type_{type}
, name_{std::move(name)} {}
inline const enum_type& evalue_index::get_type() const noexcept {
inline enum_type evalue_index::get_type() const noexcept {
return type_;
}
inline const std::string& evalue_index::get_name() const noexcept {
inline std::string&& evalue_index::get_name() && noexcept {
return std::move(name_);
}
inline const std::string& evalue_index::get_name() const& noexcept {
return name_;
}
inline void evalue_index::swap(evalue_index& other) noexcept {
std::swap(type_, other.type_);
std::swap(name_, other.name_);
}
inline std::size_t evalue_index::get_hash() const noexcept {
return detail::hash_combiner{}(detail::hash_combiner{}(type_), name_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -17,14 +16,23 @@ namespace meta_hpp
: type_{type}
, name_{std::move(name)} {}
inline const function_type& function_index::get_type() const noexcept {
inline function_type function_index::get_type() const noexcept {
return type_;
}
inline const std::string& function_index::get_name() const noexcept {
inline std::string&& function_index::get_name() && noexcept {
return std::move(name_);
}
inline const std::string& function_index::get_name() const& noexcept {
return name_;
}
inline void function_index::swap(function_index& other) noexcept {
std::swap(type_, other.type_);
std::swap(name_, other.name_);
}
inline std::size_t function_index::get_hash() const noexcept {
return detail::hash_combiner{}(detail::hash_combiner{}(type_), name_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -17,14 +16,23 @@ namespace meta_hpp
: type_{type}
, name_{std::move(name)} {}
inline const member_type& member_index::get_type() const noexcept {
inline member_type member_index::get_type() const noexcept {
return type_;
}
inline const std::string& member_index::get_name() const noexcept {
inline std::string&& member_index::get_name() && noexcept {
return std::move(name_);
}
inline const std::string& member_index::get_name() const& noexcept {
return name_;
}
inline void member_index::swap(member_index& other) noexcept {
std::swap(type_, other.type_);
std::swap(name_, other.name_);
}
inline std::size_t member_index::get_hash() const noexcept {
return detail::hash_combiner{}(detail::hash_combiner{}(type_), name_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -17,14 +16,23 @@ namespace meta_hpp
: type_{type}
, name_{std::move(name)} {}
inline const method_type& method_index::get_type() const noexcept {
inline method_type method_index::get_type() const noexcept {
return type_;
}
inline const std::string& method_index::get_name() const noexcept {
inline std::string&& method_index::get_name() && noexcept {
return std::move(name_);
}
inline const std::string& method_index::get_name() const& noexcept {
return name_;
}
inline void method_index::swap(method_index& other) noexcept {
std::swap(type_, other.type_);
std::swap(name_, other.name_);
}
inline std::size_t method_index::get_hash() const noexcept {
return detail::hash_combiner{}(detail::hash_combiner{}(type_), name_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_states.hpp"
namespace meta_hpp
@@ -16,10 +15,18 @@ namespace meta_hpp
inline scope_index::scope_index(std::string name)
: name_{std::move(name)} {}
inline const std::string& scope_index::get_name() const noexcept {
inline std::string&& scope_index::get_name() && noexcept {
return std::move(name_);
}
inline const std::string& scope_index::get_name() const& noexcept {
return name_;
}
inline void scope_index::swap(scope_index& other) noexcept {
std::swap(name_, other.name_);
}
inline std::size_t scope_index::get_hash() const noexcept {
return detail::hash_combiner{}(name_);
}

View File

@@ -8,7 +8,6 @@
#include "../meta_base.hpp"
#include "../meta_indices.hpp"
#include "../meta_registry.hpp"
#include "../meta_types.hpp"
namespace meta_hpp
@@ -17,14 +16,23 @@ namespace meta_hpp
: type_{type}
, name_{std::move(name)} {}
inline const pointer_type& variable_index::get_type() const noexcept {
inline pointer_type variable_index::get_type() const noexcept {
return type_;
}
inline const std::string& variable_index::get_name() const noexcept {
inline std::string&& variable_index::get_name() && noexcept {
return std::move(name_);
}
inline const std::string& variable_index::get_name() const& noexcept {
return name_;
}
inline void variable_index::swap(variable_index& other) noexcept {
std::swap(type_, other.type_);
std::swap(name_, other.name_);
}
inline std::size_t variable_index::get_hash() const noexcept {
return detail::hash_combiner{}(detail::hash_combiner{}(type_), name_);
}

View File

@@ -0,0 +1,83 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "meta_base.hpp"
#include "meta_states.hpp"
#include "meta_uvalue.hpp"
namespace meta_hpp
{
template < typename... Args >
uvalue invoke(const function& function, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args >
uvalue invoke(Function function_ptr, Args&&... args);
}
namespace meta_hpp
{
template < typename Instance >
uvalue invoke(const member& member, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance >
uvalue invoke(Member member_ptr, Instance&& instance);
}
namespace meta_hpp
{
template < typename Instance, typename... Args >
uvalue invoke(const method& method, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
uvalue invoke(Method method_ptr, Instance&& instance, Args&&... args);
}
namespace meta_hpp
{
template < typename... Args >
bool is_invocable_with(const function& function);
template < typename... Args >
bool is_invocable_with(const function& function, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args >
bool is_invocable_with();
template < detail::function_pointer_kind Function, typename... Args >
bool is_invocable_with(Args&&... args);
}
namespace meta_hpp
{
template < typename Instance >
bool is_invocable_with(const member& member);
template < typename Instance >
bool is_invocable_with(const member& member, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance >
bool is_invocable_with();
template < detail::member_pointer_kind Member, typename Instance >
bool is_invocable_with(Instance&& instance);
}
namespace meta_hpp
{
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method);
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
bool is_invocable_with();
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
bool is_invocable_with(Instance&& instance, Args&&... args);
}

View File

@@ -7,8 +7,12 @@
#pragma once
#include "../meta_base.hpp"
#include "../meta_invoke.hpp"
#include "../meta_states.hpp"
#include "../meta_uvalue.hpp"
#include "../meta_states/function.hpp"
#include "../meta_states/member.hpp"
#include "../meta_states/method.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
#include "../meta_detail/value_utilities/uinst.hpp"
@@ -20,14 +24,14 @@ namespace meta_hpp
return function.invoke(std::forward<Args>(args)...);
}
template < detail::function_kind Function, typename... Args >
uvalue invoke(Function&& function, Args&&... args) {
template < detail::function_pointer_kind Function, typename... Args >
uvalue invoke(Function function_ptr, Args&&... args) {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
return raw_function_invoke<function_policy::as_copy_t>(std::forward<Function>(function), vargs);
return raw_function_invoke<function_policy::as_copy_t>(function_ptr, vargs);
} else {
return raw_function_invoke<function_policy::as_copy_t>(std::forward<Function>(function), {});
return raw_function_invoke<function_policy::as_copy_t>(function_ptr, {});
}
}
}
@@ -39,11 +43,11 @@ namespace meta_hpp
return member.get(std::forward<Instance>(instance));
}
template < detail::member_kind Member, typename Instance >
uvalue invoke(Member&& member, Instance&& instance) {
template < detail::member_pointer_kind Member, typename Instance >
uvalue invoke(Member member_ptr, Instance&& instance) {
using namespace detail;
const uinst vinst{std::forward<Instance>(instance)};
return raw_member_getter<member_policy::as_copy_t>(std::forward<Member>(member), vinst);
return raw_member_getter<member_policy::as_copy_t>(member_ptr, vinst);
}
}
@@ -54,15 +58,15 @@ namespace meta_hpp
return method.invoke(std::forward<Instance>(instance), std::forward<Args>(args)...);
}
template < detail::method_kind Method, typename Instance, typename... Args >
uvalue invoke(Method&& method, Instance&& instance, Args&&... args) {
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
uvalue invoke(Method method_ptr, Instance&& instance, Args&&... args) {
using namespace detail;
const uinst vinst{std::forward<Instance>(instance)};
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
return raw_method_invoke<method_policy::as_copy_t>(std::forward<Method>(method), vinst, vargs);
return raw_method_invoke<method_policy::as_copy_t>(method_ptr, vinst, vargs);
} else {
return raw_method_invoke<method_policy::as_copy_t>(std::forward<Method>(method), vinst, {});
return raw_method_invoke<method_policy::as_copy_t>(method_ptr, vinst, {});
}
}
}
@@ -79,7 +83,7 @@ namespace meta_hpp
return function.is_invocable_with(std::forward<Args>(args)...);
}
template < detail::function_kind Function, typename... Args >
template < detail::function_pointer_kind Function, typename... Args >
bool is_invocable_with() {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
@@ -90,7 +94,7 @@ namespace meta_hpp
}
}
template < detail::function_kind Function, typename... Args >
template < detail::function_pointer_kind Function, typename... Args >
bool is_invocable_with(Args&&... args) {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
@@ -113,6 +117,20 @@ namespace meta_hpp
bool is_invocable_with(const member& member, Instance&& instance) {
return member.is_gettable_with(std::forward<Instance>(instance));
}
template < detail::member_pointer_kind Member, typename Instance >
bool is_invocable_with() {
using namespace detail;
const uinst_base vinst{type_list<Instance>{}};
return raw_member_is_gettable_with<Member>(vinst);
}
template < detail::member_pointer_kind Member, typename Instance >
bool is_invocable_with(Instance&& instance) {
using namespace detail;
const uinst_base vinst{std::forward<Instance>(instance)};
return raw_member_is_gettable_with<Member>(vinst);
}
}
namespace meta_hpp
@@ -126,28 +144,8 @@ namespace meta_hpp
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args) {
return method.is_invocable_with(std::forward<Instance>(instance), std::forward<Args>(args)...);
}
}
namespace meta_hpp
{
template < detail::member_kind Member, typename Instance >
bool is_invocable_with() {
using namespace detail;
const uinst_base vinst{type_list<Instance>{}};
return raw_member_is_gettable_with<Member>(vinst);
}
template < detail::member_kind Member, typename Instance >
bool is_invocable_with(Instance&& instance) {
using namespace detail;
const uinst_base vinst{std::forward<Instance>(instance)};
return raw_member_is_gettable_with<Member>(vinst);
}
}
namespace meta_hpp
{
template < detail::method_kind Method, typename Instance, typename... Args >
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
bool is_invocable_with() {
using namespace detail;
const uinst_base vinst{type_list<Instance>{}};
@@ -159,7 +157,7 @@ namespace meta_hpp
}
}
template < detail::method_kind Method, typename Instance, typename... Args >
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
bool is_invocable_with(Instance&& instance, Args&&... args) {
using namespace detail;
const uinst_base vinst{std::forward<Instance>(instance)};

View File

@@ -113,45 +113,65 @@ namespace meta_hpp
namespace meta_hpp
{
class argument final {
template < detail::state_family State >
class state_base {
using state_ptr = typename detail::state_traits<State>::state_ptr;
friend state_ptr detail::state_access<State>(const State&);
public:
using index_type = argument_index;
using state_ptr = detail::argument_state_ptr;
using index_type = typename detail::state_traits<State>::index_type;
argument() = default;
argument(state_ptr state) noexcept;
state_base() = default;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
explicit state_base(state_ptr state)
: state_{state} {}
[[nodiscard]] const argument_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
state_base(state_base&&) noexcept = default;
state_base(const state_base&) = default;
[[nodiscard]] const any_type& get_type() const noexcept;
state_base& operator=(state_base&&) noexcept = default;
state_base& operator=(const state_base&) = default;
[[nodiscard]] bool is_valid() const noexcept {
return state_ != nullptr;
}
[[nodiscard]] explicit operator bool() const noexcept {
return state_ != nullptr;
}
[[nodiscard]] const index_type& get_index() const noexcept {
return state_->index;
}
[[nodiscard]] const metadata_map& get_metadata() const noexcept {
return state_->metadata;
}
protected:
~state_base() = default;
state_ptr state_{};
};
}
namespace meta_hpp
{
class argument final : public state_base<argument> {
public:
using state_base<argument>::state_base;
[[nodiscard]] any_type get_type() const noexcept;
[[nodiscard]] std::size_t get_position() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
private:
state_ptr state_;
friend state_ptr detail::state_access<argument>(const argument&);
};
class constructor final {
class constructor final : public state_base<constructor> {
public:
using index_type = constructor_index;
using state_ptr = detail::constructor_state_ptr;
using state_base<constructor>::state_base;
constructor() = default;
constructor(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const constructor_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] const constructor_type& get_type() const noexcept;
[[nodiscard]] constructor_type get_type() const noexcept;
template < typename... Args >
[[nodiscard]] uvalue create(Args&&... args) const;
@@ -167,53 +187,25 @@ namespace meta_hpp
[[nodiscard]] argument get_argument(std::size_t position) const noexcept;
[[nodiscard]] const argument_list& get_arguments() const noexcept;
private:
state_ptr state_;
friend state_ptr detail::state_access<constructor>(const constructor&);
};
class destructor final {
class destructor final : public state_base<destructor> {
public:
using index_type = destructor_index;
using state_ptr = detail::destructor_state_ptr;
using state_base<destructor>::state_base;
destructor() = default;
destructor(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const destructor_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] const destructor_type& get_type() const noexcept;
[[nodiscard]] destructor_type get_type() const noexcept;
template < typename Arg >
bool destroy(Arg&& arg) const;
void destroy_at(void* mem) const;
private:
state_ptr state_;
friend state_ptr detail::state_access<destructor>(const destructor&);
};
class evalue final {
class evalue final : public state_base<evalue> {
public:
using index_type = evalue_index;
using state_ptr = detail::evalue_state_ptr;
using state_base<evalue>::state_base;
evalue() = default;
evalue(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const evalue_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] const enum_type& get_type() const noexcept;
[[nodiscard]] enum_type get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
[[nodiscard]] const uvalue& get_value() const noexcept;
@@ -224,27 +216,13 @@ namespace meta_hpp
template < typename T >
[[nodiscard]] T get_underlying_value_as() const;
private:
state_ptr state_;
friend state_ptr detail::state_access<evalue>(const evalue&);
};
class function final {
class function final : public state_base<function> {
public:
using index_type = function_index;
using state_ptr = detail::function_state_ptr;
using state_base<function>::state_base;
function() = default;
function(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const function_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] const function_type& get_type() const noexcept;
[[nodiscard]] function_type get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
template < typename... Args >
@@ -261,27 +239,13 @@ namespace meta_hpp
[[nodiscard]] argument get_argument(std::size_t position) const noexcept;
[[nodiscard]] const argument_list& get_arguments() const noexcept;
private:
state_ptr state_;
friend state_ptr detail::state_access<function>(const function&);
};
class member final {
class member final : public state_base<member> {
public:
using index_type = member_index;
using state_ptr = detail::member_state_ptr;
using state_base<member>::state_base;
member() = default;
member(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const member_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] const member_type& get_type() const noexcept;
[[nodiscard]] member_type get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
template < typename Instance >
@@ -310,27 +274,13 @@ namespace meta_hpp
template < typename Instance, typename Value >
[[nodiscard]] bool is_settable_with(Instance&& instance, Value&& value) const noexcept;
private:
state_ptr state_;
friend state_ptr detail::state_access<member>(const member&);
};
class method final {
class method final : public state_base<method> {
public:
using index_type = method_index;
using state_ptr = detail::method_state_ptr;
using state_base<method>::state_base;
method() = default;
method(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const method_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] const method_type& get_type() const noexcept;
[[nodiscard]] method_type get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
template < typename Instance, typename... Args >
@@ -347,25 +297,11 @@ namespace meta_hpp
[[nodiscard]] argument get_argument(std::size_t position) const noexcept;
[[nodiscard]] const argument_list& get_arguments() const noexcept;
private:
state_ptr state_;
friend state_ptr detail::state_access<method>(const method&);
};
class scope final {
class scope final : public state_base<scope> {
public:
using index_type = scope_index;
using state_ptr = detail::scope_state_ptr;
scope() = default;
scope(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const scope_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
using state_base<scope>::state_base;
[[nodiscard]] const std::string& get_name() const noexcept;
@@ -383,27 +319,13 @@ namespace meta_hpp
[[nodiscard]] function get_function_with(std::string_view name, Iter first, Iter last) const noexcept;
[[nodiscard]] function get_function_with(std::string_view name, std::span<const any_type> args) const noexcept;
[[nodiscard]] function get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept;
private:
state_ptr state_;
friend state_ptr detail::state_access<scope>(const scope&);
};
class variable final {
class variable final : public state_base<variable> {
public:
using index_type = variable_index;
using state_ptr = detail::variable_state_ptr;
using state_base<variable>::state_base;
variable() = default;
variable(state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const variable_index& get_index() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] const pointer_type& get_type() const noexcept;
[[nodiscard]] pointer_type get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
[[nodiscard]] uvalue get() const;
@@ -424,22 +346,28 @@ namespace meta_hpp
template < typename Value >
[[nodiscard]] bool is_settable_with(Value&& value) const noexcept;
};
}
private:
state_ptr state_;
friend state_ptr detail::state_access<variable>(const variable&);
namespace std
{
template < meta_hpp::detail::state_family State >
struct hash<State> {
size_t operator()(const State& state) const noexcept {
return state.is_valid() ? state.get_index().get_hash() : 0;
}
};
}
namespace meta_hpp
{
template < detail::state_family T, detail::state_family U >
[[nodiscard]] bool operator==(const T& l, const U& r) noexcept {
template < detail::state_family L, detail::state_family R >
[[nodiscard]] bool operator==(const L& l, const R& r) noexcept {
return l.is_valid() == r.is_valid() && (!l.is_valid() || l.get_index() == r.get_index());
}
template < detail::state_family T, detail::state_family U >
[[nodiscard]] std::strong_ordering operator<=>(const T& l, const U& r) noexcept {
template < detail::state_family L, detail::state_family R >
[[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept {
if ( const std::strong_ordering cmp{l.is_valid() <=> r.is_valid()}; cmp != std::strong_ordering::equal ) {
return cmp;
}
@@ -449,15 +377,13 @@ namespace meta_hpp
namespace meta_hpp
{
template < detail::state_family T, typename U >
requires std::is_same_v<U, typename T::index_type>
[[nodiscard]] bool operator==(const T& l, const U& r) noexcept {
template < detail::state_family L, detail::index_family R >
[[nodiscard]] bool operator==(const L& l, const R& r) noexcept {
return l.is_valid() && l.get_index() == r;
}
template < detail::state_family T, typename U >
requires std::is_same_v<U, typename T::index_type>
[[nodiscard]] std::strong_ordering operator<=>(const T& l, const U& r) noexcept {
template < detail::state_family L, detail::index_family R >
[[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept {
return l.is_valid() ? l.get_index() <=> r : std::strong_ordering::less;
}
}
@@ -531,8 +457,8 @@ namespace meta_hpp::detail
is_invocable_with_impl is_invocable_with{};
argument_list arguments{};
template < function_policy_kind Policy, function_kind Function >
[[nodiscard]] static function_state_ptr make(std::string name, Function function, metadata_map metadata);
template < function_policy_kind Policy, function_pointer_kind Function >
[[nodiscard]] static function_state_ptr make(std::string name, Function function_ptr, metadata_map metadata);
explicit function_state(function_index index, metadata_map metadata);
};
@@ -551,8 +477,8 @@ namespace meta_hpp::detail
is_gettable_with_impl is_gettable_with{};
is_settable_with_impl is_settable_with{};
template < member_policy_kind Policy, member_kind Member >
[[nodiscard]] static member_state_ptr make(std::string name, Member member, metadata_map metadata);
template < member_policy_kind Policy, member_pointer_kind Member >
[[nodiscard]] static member_state_ptr make(std::string name, Member member_ptr, metadata_map metadata);
explicit member_state(member_index index, metadata_map metadata);
};
@@ -567,8 +493,8 @@ namespace meta_hpp::detail
is_invocable_with_impl is_invocable_with{};
argument_list arguments{};
template < method_policy_kind Policy, method_kind Method >
[[nodiscard]] static method_state_ptr make(std::string name, Method method, metadata_map metadata);
template < method_policy_kind Policy, method_pointer_kind Method >
[[nodiscard]] static method_state_ptr make(std::string name, Method method_ptr, metadata_map metadata);
explicit method_state(method_index index, metadata_map metadata);
};
@@ -597,7 +523,7 @@ namespace meta_hpp::detail
is_settable_with_impl is_settable_with{};
template < variable_policy_kind Policy, pointer_kind Pointer >
[[nodiscard]] static variable_state_ptr make(std::string name, Pointer pointer, metadata_map metadata);
[[nodiscard]] static variable_state_ptr make(std::string name, Pointer variable_ptr, metadata_map metadata);
explicit variable_state(variable_index index, metadata_map metadata);
};
}

View File

@@ -24,27 +24,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline argument::argument(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool argument::is_valid() const noexcept {
return !!state_;
}
inline argument::operator bool() const noexcept {
return is_valid();
}
inline const argument_index& argument::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& argument::get_metadata() const noexcept {
return state_->metadata;
}
inline const any_type& argument::get_type() const noexcept {
inline any_type argument::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -32,15 +32,17 @@ namespace meta_hpp::detail
static_assert(as_object || as_raw_ptr || as_shared_ptr);
if ( args.size() != ct::arity ) {
META_HPP_THROW_AS(exception, "an attempt to call a constructor with an incorrect arity");
}
META_HPP_THROW_IF( //
args.size() != ct::arity,
"an attempt to call a constructor with an incorrect arity"
);
return std::invoke(
[args]<std::size_t... Is>(std::index_sequence<Is...>)->uvalue {
if ( !(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()) ) {
META_HPP_THROW_AS(exception, "an attempt to call a constructor with incorrect argument types");
}
META_HPP_THROW_IF( //
!(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()),
"an attempt to call a constructor with incorrect argument types"
);
if constexpr ( as_object ) {
return make_uvalue<class_type>(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
@@ -64,17 +66,22 @@ namespace meta_hpp::detail
using class_type = typename ct::class_type;
using argument_types = typename ct::argument_types;
if ( args.size() != ct::arity ) {
META_HPP_THROW_AS(exception, "an attempt to call a constructor with an incorrect arity");
}
META_HPP_THROW_IF( //
args.size() != ct::arity,
"an attempt to call a constructor with an incorrect arity"
);
return std::invoke(
[ mem, args ]<std::size_t... Is>(std::index_sequence<Is...>)->uvalue {
if ( !(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()) ) {
META_HPP_THROW_AS(exception, "an attempt to call a constructor with incorrect argument types");
}
return uvalue{
std::construct_at(static_cast<class_type*>(mem), args[Is].cast<type_list_at_t<Is, argument_types>>()...)};
META_HPP_THROW_IF( //
!(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()),
"an attempt to call a constructor with incorrect argument types"
);
return uvalue{std::construct_at( //
static_cast<class_type*>(mem),
args[Is].cast<type_list_at_t<Is, argument_types>>()...
)};
},
std::make_index_sequence<ct::arity>()
);
@@ -152,26 +159,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline constructor::constructor(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool constructor::is_valid() const noexcept {
return !!state_;
}
inline constructor::operator bool() const noexcept {
return is_valid();
}
inline const constructor_index& constructor::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& constructor::get_metadata() const noexcept {
return state_->metadata;
}
inline const constructor_type& constructor::get_type() const noexcept {
inline constructor_type constructor::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -66,26 +66,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline destructor::destructor(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool destructor::is_valid() const noexcept {
return !!state_;
}
inline destructor::operator bool() const noexcept {
return is_valid();
}
inline const destructor_index& destructor::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& destructor::get_metadata() const noexcept {
return state_->metadata;
}
inline const destructor_type& destructor::get_type() const noexcept {
inline destructor_type destructor::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -28,26 +28,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline evalue::evalue(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool evalue::is_valid() const noexcept {
return !!state_;
}
inline evalue::operator bool() const noexcept {
return is_valid();
}
inline const evalue_index& evalue::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& evalue::get_metadata() const noexcept {
return state_->metadata;
}
inline const enum_type& evalue::get_type() const noexcept {
inline enum_type evalue::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -14,8 +14,8 @@
namespace meta_hpp::detail
{
template < function_policy_kind Policy, function_kind Function >
uvalue raw_function_invoke(const Function& function, std::span<const uarg> args) {
template < function_policy_kind Policy, function_pointer_kind Function >
uvalue raw_function_invoke(Function function_ptr, std::span<const uarg> args) {
using ft = function_traits<Function>;
using return_type = typename ft::return_type;
using argument_types = typename ft::argument_types;
@@ -34,24 +34,26 @@ namespace meta_hpp::detail
static_assert(as_copy || as_void || ref_as_ptr);
if ( args.size() != ft::arity ) {
META_HPP_THROW_AS(exception, "an attempt to call a function with an incorrect arity");
}
META_HPP_THROW_IF( //
args.size() != ft::arity,
"an attempt to call a function with an incorrect arity"
);
return std::invoke(
[&function, args ]<std::size_t... Is>(std::index_sequence<Is...>)->uvalue {
if ( !(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()) ) {
META_HPP_THROW_AS(exception, "an attempt to call a function with incorrect argument types");
}
[ function_ptr, args ]<std::size_t... Is>(std::index_sequence<Is...>)->uvalue {
META_HPP_THROW_IF( //
!(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()),
"an attempt to call a function with incorrect argument types"
);
if constexpr ( std::is_void_v<return_type> ) {
function(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
function_ptr(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else if constexpr ( std::is_same_v<Policy, function_policy::discard_return_t> ) {
std::ignore = function(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
std::ignore = function_ptr(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else {
return_type&& return_value = function(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return_type&& return_value = function_ptr(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
if constexpr ( ref_as_ptr ) {
return uvalue{std::addressof(return_value)};
@@ -64,7 +66,7 @@ namespace meta_hpp::detail
);
}
template < function_kind Function >
template < function_pointer_kind Function >
bool raw_function_is_invocable_with(std::span<const uarg_base> args) {
using ft = function_traits<Function>;
using argument_types = typename ft::argument_types;
@@ -84,19 +86,19 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < function_policy_kind Policy, function_kind Function >
function_state::invoke_impl make_function_invoke(Function function) {
return [function = std::move(function)](std::span<const uarg> args) { //
return raw_function_invoke<Policy>(function, args);
template < function_policy_kind Policy, function_pointer_kind Function >
function_state::invoke_impl make_function_invoke(Function function_ptr) {
return [function_ptr](std::span<const uarg> args) { //
return raw_function_invoke<Policy>(function_ptr, args);
};
}
template < function_kind Function >
template < function_pointer_kind Function >
function_state::is_invocable_with_impl make_function_is_invocable_with() {
return &raw_function_is_invocable_with<Function>;
}
template < function_kind Function >
template < function_pointer_kind Function >
argument_list make_function_arguments() {
using ft = function_traits<Function>;
using ft_argument_types = typename ft::argument_types;
@@ -120,10 +122,10 @@ namespace meta_hpp::detail
: index{std::move(nindex)}
, metadata{std::move(nmetadata)} {}
template < function_policy_kind Policy, function_kind Function >
function_state_ptr function_state::make(std::string name, Function function, metadata_map metadata) {
template < function_policy_kind Policy, function_pointer_kind Function >
function_state_ptr function_state::make(std::string name, Function function_ptr, metadata_map metadata) {
function_state state{function_index{resolve_type<Function>(), std::move(name)}, std::move(metadata)};
state.invoke = make_function_invoke<Policy>(std::move(function));
state.invoke = make_function_invoke<Policy>(function_ptr);
state.is_invocable_with = make_function_is_invocable_with<Function>();
state.arguments = make_function_arguments<Function>();
return make_intrusive<function_state>(std::move(state));
@@ -132,26 +134,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline function::function(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool function::is_valid() const noexcept {
return !!state_;
}
inline function::operator bool() const noexcept {
return is_valid();
}
inline const function_index& function::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& function::get_metadata() const noexcept {
return state_->metadata;
}
inline const function_type& function::get_type() const noexcept {
inline function_type function::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -15,8 +15,8 @@
namespace meta_hpp::detail
{
template < member_policy_kind Policy, member_kind Member >
uvalue raw_member_getter(const Member& member, const uinst& inst) {
template < member_policy_kind Policy, member_pointer_kind Member >
uvalue raw_member_getter(Member member_ptr, const uinst& inst) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
@@ -33,12 +33,13 @@ namespace meta_hpp::detail
static_assert(as_copy || as_ptr || as_ref_wrap);
if ( !inst.can_cast_to<const class_type>() ) {
META_HPP_THROW_AS(exception, "an attempt to get a member with an incorrect instance type");
}
META_HPP_THROW_IF( //
!inst.can_cast_to<const class_type>(),
"an attempt to get a member with an incorrect instance type"
);
if ( inst.is_inst_const() ) {
auto&& return_value = inst.cast<const class_type>().*member;
auto&& return_value = inst.cast<const class_type>().*member_ptr;
if constexpr ( as_copy ) {
return uvalue{std::forward<decltype(return_value)>(return_value)};
@@ -52,7 +53,7 @@ namespace meta_hpp::detail
return uvalue{std::ref(return_value)};
}
} else {
auto&& return_value = inst.cast<class_type>().*member;
auto&& return_value = inst.cast<class_type>().*member_ptr;
if constexpr ( as_copy ) {
return uvalue{std::forward<decltype(return_value)>(return_value)};
@@ -68,7 +69,7 @@ namespace meta_hpp::detail
}
}
template < member_kind Member >
template < member_pointer_kind Member >
bool raw_member_is_gettable_with(const uinst_base& inst) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
@@ -79,32 +80,35 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < member_kind Member >
void raw_member_setter([[maybe_unused]] const Member& member, const uinst& inst, const uarg& arg) {
template < member_pointer_kind Member >
void raw_member_setter([[maybe_unused]] Member member_ptr, const uinst& inst, const uarg& arg) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
if constexpr ( std::is_const_v<value_type> ) {
META_HPP_THROW_AS(exception, "an attempt to set a constant member");
META_HPP_THROW("an attempt to set a constant member");
} else {
if ( inst.is_inst_const() ) {
META_HPP_THROW_AS(exception, "an attempt to set a member with an const instance type");
}
META_HPP_THROW_IF( //
inst.is_inst_const(),
"an attempt to set a member with an const instance type"
);
if ( !inst.can_cast_to<class_type>() ) {
META_HPP_THROW_AS(exception, "an attempt to set a member with an incorrect instance type");
}
META_HPP_THROW_IF( //
!inst.can_cast_to<class_type>(),
"an attempt to set a member with an incorrect instance type"
);
if ( !arg.can_cast_to<value_type>() ) {
META_HPP_THROW_AS(exception, "an attempt to set a member with an incorrect argument type");
}
META_HPP_THROW_IF( //
!arg.can_cast_to<value_type>(),
"an attempt to set a member with an incorrect argument type"
);
inst.cast<class_type>().*member = arg.cast<value_type>();
inst.cast<class_type>().*member_ptr = arg.cast<value_type>();
}
}
template < member_kind Member >
template < member_pointer_kind Member >
bool raw_member_is_settable_with(const uinst_base& inst, const uarg_base& arg) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
@@ -117,26 +121,26 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < member_policy_kind Policy, member_kind Member >
member_state::getter_impl make_member_getter(Member member) {
return [member = std::move(member)](const uinst& inst) { //
return raw_member_getter<Policy>(member, inst);
template < member_policy_kind Policy, member_pointer_kind Member >
member_state::getter_impl make_member_getter(Member member_ptr) {
return [member_ptr](const uinst& inst) { //
return raw_member_getter<Policy>(member_ptr, inst);
};
}
template < member_kind Member >
template < member_pointer_kind Member >
member_state::is_gettable_with_impl make_member_is_gettable_with() {
return &raw_member_is_gettable_with<Member>;
}
template < member_kind Member >
member_state::setter_impl make_member_setter(Member member) {
return [member = std::move(member)](const uinst& inst, const uarg& arg) { //
return raw_member_setter(member, inst, arg);
template < member_pointer_kind Member >
member_state::setter_impl make_member_setter(Member member_ptr) {
return [member_ptr](const uinst& inst, const uarg& arg) { //
return raw_member_setter(member_ptr, inst, arg);
};
}
template < member_kind Member >
template < member_pointer_kind Member >
member_state::is_settable_with_impl make_member_is_settable_with() {
return &raw_member_is_settable_with<Member>;
}
@@ -148,11 +152,11 @@ namespace meta_hpp::detail
: index{std::move(nindex)}
, metadata{std::move(nmetadata)} {}
template < member_policy_kind Policy, member_kind Member >
member_state_ptr member_state::make(std::string name, Member member, metadata_map metadata) {
template < member_policy_kind Policy, member_pointer_kind Member >
member_state_ptr member_state::make(std::string name, Member member_ptr, metadata_map metadata) {
member_state state{member_index{resolve_type<Member>(), std::move(name)}, std::move(metadata)};
state.getter = make_member_getter<Policy>(member);
state.setter = make_member_setter(member);
state.getter = make_member_getter<Policy>(member_ptr);
state.setter = make_member_setter(member_ptr);
state.is_gettable_with = make_member_is_gettable_with<Member>();
state.is_settable_with = make_member_is_settable_with<Member>();
return make_intrusive<member_state>(std::move(state));
@@ -161,26 +165,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline member::member(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool member::is_valid() const noexcept {
return !!state_;
}
inline member::operator bool() const noexcept {
return is_valid();
}
inline const member_index& member::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& member::get_metadata() const noexcept {
return state_->metadata;
}
inline const member_type& member::get_type() const noexcept {
inline member_type member::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -15,8 +15,8 @@
namespace meta_hpp::detail
{
template < method_policy_kind Policy, method_kind Method >
uvalue raw_method_invoke(const Method& method, const uinst& inst, std::span<const uarg> args) {
template < method_policy_kind Policy, method_pointer_kind Method >
uvalue raw_method_invoke(Method method_ptr, const uinst& inst, std::span<const uarg> args) {
using mt = method_traits<Method>;
using return_type = typename mt::return_type;
using qualified_type = typename mt::qualified_type;
@@ -36,28 +36,32 @@ namespace meta_hpp::detail
static_assert(as_copy || as_void || ref_as_ptr);
if ( args.size() != mt::arity ) {
META_HPP_THROW_AS(exception, "an attempt to call a method with an incorrect arity");
}
META_HPP_THROW_IF( //
args.size() != mt::arity,
"an attempt to call a method with an incorrect arity"
);
if ( !inst.can_cast_to<qualified_type>() ) {
META_HPP_THROW_AS(exception, "an attempt to call a method with an incorrect instance type");
}
META_HPP_THROW_IF( //
!inst.can_cast_to<qualified_type>(),
"an attempt to call a method with an incorrect instance type"
);
return std::invoke(
[&method, &inst, args ]<std::size_t... Is>(std::index_sequence<Is...>)->uvalue {
if ( !(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()) ) {
META_HPP_THROW_AS(exception, "an attempt to call a method with incorrect argument types");
}
[ method_ptr, &inst, args ]<std::size_t... Is>(std::index_sequence<Is...>)->uvalue {
META_HPP_THROW_IF( //
!(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()),
"an attempt to call a method with incorrect argument types"
);
if constexpr ( std::is_void_v<return_type> ) {
(inst.cast<qualified_type>().*method)(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
(inst.cast<qualified_type>().*method_ptr)(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return uvalue{};
} else if constexpr ( std::is_same_v<Policy, method_policy::discard_return_t> ) {
std::ignore = (inst.cast<qualified_type>().*method)(args[Is].cast<type_list_at_t<Is, argument_types>>()...);
std::ignore = (inst.cast<qualified_type>().*method_ptr)(args[Is].cast<type_list_at_t<Is, argument_types>>()...
);
return uvalue{};
} else {
return_type&& return_value = (inst.cast<qualified_type>().*method)(
return_type&& return_value = (inst.cast<qualified_type>().*method_ptr)(
args[Is].cast<type_list_at_t<Is, argument_types>>()...
);
@@ -72,7 +76,7 @@ namespace meta_hpp::detail
);
}
template < method_kind Method >
template < method_pointer_kind Method >
bool raw_method_is_invocable_with(const uinst_base& inst, std::span<const uarg_base> args) {
using mt = method_traits<Method>;
using qualified_type = typename mt::qualified_type;
@@ -97,19 +101,19 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < method_policy_kind Policy, method_kind Method >
method_state::invoke_impl make_method_invoke(Method method) {
return [method = std::move(method)](const uinst& inst, std::span<const uarg> args) {
return raw_method_invoke<Policy>(method, inst, args);
template < method_policy_kind Policy, method_pointer_kind Method >
method_state::invoke_impl make_method_invoke(Method method_ptr) {
return [method_ptr](const uinst& inst, std::span<const uarg> args) {
return raw_method_invoke<Policy>(method_ptr, inst, args);
};
}
template < method_kind Method >
template < method_pointer_kind Method >
method_state::is_invocable_with_impl make_method_is_invocable_with() {
return &raw_method_is_invocable_with<Method>;
}
template < method_kind Method >
template < method_pointer_kind Method >
argument_list make_method_arguments() {
using mt = method_traits<Method>;
using mt_argument_types = typename mt::argument_types;
@@ -133,10 +137,10 @@ namespace meta_hpp::detail
: index{std::move(nindex)}
, metadata{std::move(nmetadata)} {}
template < method_policy_kind Policy, method_kind Method >
method_state_ptr method_state::make(std::string name, Method method, metadata_map metadata) {
template < method_policy_kind Policy, method_pointer_kind Method >
method_state_ptr method_state::make(std::string name, Method method_ptr, metadata_map metadata) {
method_state state{method_index{resolve_type<Method>(), std::move(name)}, std::move(metadata)};
state.invoke = make_method_invoke<Policy>(std::move(method));
state.invoke = make_method_invoke<Policy>(method_ptr);
state.is_invocable_with = make_method_is_invocable_with<Method>();
state.arguments = make_method_arguments<Method>();
return make_intrusive<method_state>(std::move(state));
@@ -145,26 +149,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline method::method(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool method::is_valid() const noexcept {
return !!state_;
}
inline method::operator bool() const noexcept {
return is_valid();
}
inline const method_index& method::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& method::get_metadata() const noexcept {
return state_->metadata;
}
inline const method_type& method::get_type() const noexcept {
inline method_type method::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -31,25 +31,6 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline scope::scope(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool scope::is_valid() const noexcept {
return !!state_;
}
inline scope::operator bool() const noexcept {
return is_valid();
}
inline const scope_index& scope::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& scope::get_metadata() const noexcept {
return state_->metadata;
}
inline const std::string& scope::get_name() const noexcept {
return state_->index.get_name();
}

View File

@@ -15,7 +15,7 @@
namespace meta_hpp::detail
{
template < variable_policy_kind Policy, pointer_kind Pointer >
uvalue raw_variable_getter(const Pointer& pointer) {
uvalue raw_variable_getter(Pointer variable_ptr) {
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;
@@ -31,7 +31,7 @@ namespace meta_hpp::detail
static_assert(as_copy || as_ptr || as_ref_wrap);
auto&& return_value = *pointer;
auto&& return_value = *variable_ptr;
if constexpr ( as_copy ) {
return uvalue{std::forward<decltype(return_value)>(return_value)};
@@ -47,17 +47,18 @@ namespace meta_hpp::detail
}
template < pointer_kind Pointer >
void raw_variable_setter([[maybe_unused]] const Pointer& pointer, const uarg& arg) {
void raw_variable_setter([[maybe_unused]] Pointer variable_ptr, const uarg& arg) {
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;
if constexpr ( std::is_const_v<data_type> ) {
META_HPP_THROW_AS(exception, "an attempt to set a constant variable");
META_HPP_THROW("an attempt to set a constant variable");
} else {
if ( !arg.can_cast_to<data_type>() ) {
META_HPP_THROW_AS(exception, "an attempt to set a variable with an incorrect argument type");
}
*pointer = arg.cast<data_type>();
META_HPP_THROW_IF( //
!arg.can_cast_to<data_type>(),
"an attempt to set a variable with an incorrect argument type"
);
*variable_ptr = arg.cast<data_type>();
}
}
@@ -73,16 +74,16 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < variable_policy_kind Policy, pointer_kind Pointer >
variable_state::getter_impl make_variable_getter(Pointer pointer) {
return [pointer = std::move(pointer)]() { //
return raw_variable_getter<Policy>(pointer);
variable_state::getter_impl make_variable_getter(Pointer variable_ptr) {
return [variable_ptr]() { //
return raw_variable_getter<Policy>(variable_ptr);
};
}
template < pointer_kind Pointer >
variable_state::setter_impl make_variable_setter(Pointer pointer) {
return [pointer = std::move(pointer)](const uarg& arg) { //
return raw_variable_setter(pointer, arg);
variable_state::setter_impl make_variable_setter(Pointer variable_ptr) {
return [variable_ptr](const uarg& arg) { //
return raw_variable_setter(variable_ptr, arg);
};
}
@@ -99,10 +100,10 @@ namespace meta_hpp::detail
, metadata{std::move(nmetadata)} {}
template < variable_policy_kind Policy, pointer_kind Pointer >
variable_state_ptr variable_state::make(std::string name, Pointer pointer, metadata_map metadata) {
variable_state_ptr variable_state::make(std::string name, Pointer variable_ptr, metadata_map metadata) {
variable_state state{variable_index{resolve_type<Pointer>(), std::move(name)}, std::move(metadata)};
state.getter = make_variable_getter<Policy>(pointer);
state.setter = make_variable_setter(pointer);
state.getter = make_variable_getter<Policy>(variable_ptr);
state.setter = make_variable_setter(variable_ptr);
state.is_settable_with = make_variable_is_settable_with<Pointer>();
return make_intrusive<variable_state>(std::move(state));
}
@@ -110,26 +111,7 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline variable::variable(state_ptr state) noexcept
: state_{std::move(state)} {}
inline bool variable::is_valid() const noexcept {
return !!state_;
}
inline variable::operator bool() const noexcept {
return is_valid();
}
inline const variable_index& variable::get_index() const noexcept {
return state_->index;
}
inline const metadata_map& variable::get_metadata() const noexcept {
return state_->metadata;
}
inline const pointer_type& variable::get_type() const noexcept {
inline pointer_type variable::get_type() const noexcept {
return state_->index.get_type();
}

View File

@@ -10,18 +10,6 @@
#include "meta_detail/type_family.hpp"
#include "meta_detail/type_traits/array_traits.hpp"
#include "meta_detail/type_traits/class_traits.hpp"
#include "meta_detail/type_traits/constructor_traits.hpp"
#include "meta_detail/type_traits/destructor_traits.hpp"
#include "meta_detail/type_traits/enum_traits.hpp"
#include "meta_detail/type_traits/function_traits.hpp"
#include "meta_detail/type_traits/member_traits.hpp"
#include "meta_detail/type_traits/method_traits.hpp"
#include "meta_detail/type_traits/number_traits.hpp"
#include "meta_detail/type_traits/pointer_traits.hpp"
#include "meta_detail/type_traits/reference_traits.hpp"
namespace meta_hpp
{
using detail::array_bitflags;
@@ -60,34 +48,58 @@ namespace meta_hpp
namespace meta_hpp
{
class any_type final {
template < detail::type_family Type >
class type_base {
using data_ptr = typename detail::type_traits<Type>::data_ptr;
friend data_ptr detail::type_access<Type>(const Type&);
public:
using data_ptr = detail::type_data_base*;
type_base() = default;
any_type() = default;
any_type(data_ptr data);
explicit type_base(data_ptr data)
: data_{data} {}
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
type_base(type_base&&) noexcept = default;
type_base(const type_base&) = default;
[[nodiscard]] type_id get_id() const noexcept;
[[nodiscard]] type_kind get_kind() const noexcept;
type_base& operator=(type_base&&) noexcept = default;
type_base& operator=(const type_base&) = default;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] bool is_valid() const noexcept {
return data_ != nullptr;
}
any_type(const array_type& other) noexcept;
any_type(const class_type& other) noexcept;
any_type(const constructor_type& other) noexcept;
any_type(const destructor_type& other) noexcept;
any_type(const enum_type& other) noexcept;
any_type(const function_type& other) noexcept;
any_type(const member_type& other) noexcept;
any_type(const method_type& other) noexcept;
any_type(const nullptr_type& other) noexcept;
any_type(const number_type& other) noexcept;
any_type(const pointer_type& other) noexcept;
any_type(const reference_type& other) noexcept;
any_type(const void_type& other) noexcept;
[[nodiscard]] explicit operator bool() const noexcept {
return data_ != nullptr;
}
[[nodiscard]] type_id get_id() const noexcept {
return data_->id;
}
[[nodiscard]] type_kind get_kind() const noexcept {
return data_->kind;
}
[[nodiscard]] const metadata_map& get_metadata() const noexcept {
return data_->metadata;
}
protected:
~type_base() = default;
data_ptr data_{};
};
}
namespace meta_hpp
{
class any_type final : public type_base<any_type> {
public:
using type_base<any_type>::type_base;
template < detail::type_family Type >
any_type(const Type& other) noexcept;
template < detail::type_family Type >
[[nodiscard]] bool is() const noexcept;
@@ -122,49 +134,21 @@ namespace meta_hpp
[[nodiscard]] pointer_type as_pointer() const noexcept;
[[nodiscard]] reference_type as_reference() const noexcept;
[[nodiscard]] void_type as_void() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<any_type>(const any_type&);
};
class array_type final {
class array_type final : public type_base<array_type> {
public:
using data_ptr = detail::array_type_data*;
inline static constexpr type_kind kind{type_kind::array_};
array_type() = default;
array_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<array_type>::type_base;
[[nodiscard]] array_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] std::size_t get_extent() const noexcept;
[[nodiscard]] any_type get_data_type() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<array_type>(const array_type&);
};
class class_type final {
class class_type final : public type_base<class_type> {
public:
using data_ptr = detail::class_type_data*;
inline static constexpr type_kind kind{type_kind::class_};
class_type() = default;
class_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<class_type>::type_base;
[[nodiscard]] class_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] std::size_t get_size() const noexcept;
[[nodiscard]] std::size_t get_align() const noexcept;
@@ -227,73 +211,31 @@ namespace meta_hpp
[[nodiscard]] method get_method_with(std::string_view name, Iter first, Iter last) const noexcept;
[[nodiscard]] method get_method_with(std::string_view name, std::span<const any_type> args) const noexcept;
[[nodiscard]] method get_method_with(std::string_view name, std::initializer_list<any_type> args) const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<class_type>(const class_type&);
};
class constructor_type final {
class constructor_type final : public type_base<constructor_type> {
public:
using data_ptr = detail::constructor_type_data*;
inline static constexpr type_kind kind{type_kind::constructor_};
constructor_type() = default;
constructor_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<constructor_type>::type_base;
[[nodiscard]] constructor_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] std::size_t get_arity() const noexcept;
[[nodiscard]] class_type get_owner_type() const noexcept;
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
[[nodiscard]] const any_type_list& get_argument_types() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<constructor_type>(const constructor_type&);
};
class destructor_type final {
class destructor_type final : public type_base<destructor_type> {
public:
using data_ptr = detail::destructor_type_data*;
inline static constexpr type_kind kind{type_kind::destructor_};
destructor_type() = default;
destructor_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<destructor_type>::type_base;
[[nodiscard]] destructor_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] class_type get_owner_type() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<destructor_type>(const destructor_type&);
};
class enum_type final {
class enum_type final : public type_base<enum_type> {
public:
using data_ptr = detail::enum_type_data*;
inline static constexpr type_kind kind{type_kind::enum_};
enum_type() = default;
enum_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<enum_type>::type_base;
[[nodiscard]] enum_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] number_type get_underlying_type() const noexcept;
@@ -307,211 +249,95 @@ namespace meta_hpp
template < typename T >
[[nodiscard]] T name_to_value_as(std::string_view name) const;
private:
data_ptr data_{};
friend data_ptr detail::type_access<enum_type>(const enum_type&);
};
class function_type final {
class function_type final : public type_base<function_type> {
public:
using data_ptr = detail::function_type_data*;
inline static constexpr type_kind kind{type_kind::function_};
function_type() = default;
function_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<function_type>::type_base;
[[nodiscard]] function_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] std::size_t get_arity() const noexcept;
[[nodiscard]] any_type get_return_type() const noexcept;
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
[[nodiscard]] const any_type_list& get_argument_types() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<function_type>(const function_type&);
};
class member_type final {
class member_type final : public type_base<member_type> {
public:
using data_ptr = detail::member_type_data*;
inline static constexpr type_kind kind{type_kind::member_};
member_type() = default;
member_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<member_type>::type_base;
[[nodiscard]] member_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] class_type get_owner_type() const noexcept;
[[nodiscard]] any_type get_value_type() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<member_type>(const member_type&);
};
class method_type final {
class method_type final : public type_base<method_type> {
public:
using data_ptr = detail::method_type_data*;
inline static constexpr type_kind kind{type_kind::method_};
method_type() = default;
method_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<method_type>::type_base;
[[nodiscard]] method_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] std::size_t get_arity() const noexcept;
[[nodiscard]] class_type get_owner_type() const noexcept;
[[nodiscard]] any_type get_return_type() const noexcept;
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
[[nodiscard]] const any_type_list& get_argument_types() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<method_type>(const method_type&);
};
class nullptr_type final {
class nullptr_type final : public type_base<nullptr_type> {
public:
using data_ptr = detail::nullptr_type_data*;
inline static constexpr type_kind kind{type_kind::nullptr_};
nullptr_type() = default;
nullptr_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<nullptr_type>(const nullptr_type&);
using type_base<nullptr_type>::type_base;
};
class number_type final {
class number_type final : public type_base<number_type> {
public:
using data_ptr = detail::number_type_data*;
inline static constexpr type_kind kind{type_kind::number_};
number_type() = default;
number_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<number_type>::type_base;
[[nodiscard]] number_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] std::size_t get_size() const noexcept;
[[nodiscard]] std::size_t get_align() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<number_type>(const number_type&);
};
class pointer_type final {
class pointer_type final : public type_base<pointer_type> {
public:
using data_ptr = detail::pointer_type_data*;
inline static constexpr type_kind kind{type_kind::pointer_};
pointer_type() = default;
pointer_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<pointer_type>::type_base;
[[nodiscard]] pointer_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] any_type get_data_type() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<pointer_type>(const pointer_type&);
};
class reference_type final {
class reference_type final : public type_base<reference_type> {
public:
using data_ptr = detail::reference_type_data*;
inline static constexpr type_kind kind{type_kind::reference_};
reference_type() = default;
reference_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
using type_base<reference_type>::type_base;
[[nodiscard]] reference_bitflags get_flags() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
[[nodiscard]] any_type get_data_type() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<reference_type>(const reference_type&);
};
class void_type final {
class void_type final : public type_base<void_type> {
public:
using data_ptr = detail::void_type_data*;
inline static constexpr type_kind kind{type_kind::void_};
void_type() = default;
void_type(data_ptr data);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept;
[[nodiscard]] const metadata_map& get_metadata() const noexcept;
private:
data_ptr data_{};
friend data_ptr detail::type_access<void_type>(const void_type&);
using type_base<void_type>::type_base;
};
}
namespace std
{
template < meta_hpp::detail::type_family T >
struct hash<T> {
size_t operator()(const T& t) const noexcept {
return meta_hpp::detail::hash_combiner{}(t.get_id());
template < meta_hpp::detail::type_family Type >
struct hash<Type> {
size_t operator()(const Type& type) const noexcept {
return type.is_valid() ? type.get_id().get_hash() : 0;
}
};
}
namespace meta_hpp
{
template < detail::type_family T, detail::type_family U >
[[nodiscard]] bool operator==(const T& l, const U& r) noexcept {
template < detail::type_family L, detail::type_family R >
[[nodiscard]] bool operator==(const L& l, const R& r) noexcept {
return l.is_valid() == r.is_valid() && (!l.is_valid() || l.get_id() == r.get_id());
}
template < detail::type_family T, detail::type_family U >
[[nodiscard]] std::strong_ordering operator<=>(const T& l, const U& r) noexcept {
template < detail::type_family L, detail::type_family R >
[[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept {
if ( const std::strong_ordering cmp{l.is_valid() <=> r.is_valid()}; cmp != std::strong_ordering::equal ) {
return cmp;
}
@@ -521,13 +347,13 @@ namespace meta_hpp
namespace meta_hpp
{
template < detail::type_family T >
[[nodiscard]] bool operator==(const T& l, type_id r) noexcept {
template < detail::type_family L >
[[nodiscard]] bool operator==(const L& l, type_id r) noexcept {
return l.is_valid() && l.get_id() == r;
}
template < detail::type_family T >
[[nodiscard]] std::strong_ordering operator<=>(const T& l, type_id r) noexcept {
template < detail::type_family L >
[[nodiscard]] std::strong_ordering operator<=>(const L& l, type_id r) noexcept {
return l.is_valid() ? l.get_id() <=> r : std::strong_ordering::less;
}
}
@@ -621,7 +447,7 @@ namespace meta_hpp::detail
const any_type return_type;
const any_type_list argument_types;
template < function_kind Function >
template < function_pointer_kind Function >
explicit function_type_data(type_list<Function>);
};
@@ -630,7 +456,7 @@ namespace meta_hpp::detail
const class_type owner_type;
const any_type value_type;
template < member_kind Member >
template < member_pointer_kind Member >
explicit member_type_data(type_list<Member>);
};
@@ -640,7 +466,7 @@ namespace meta_hpp::detail
const any_type return_type;
const any_type_list argument_types;
template < method_kind Method >
template < method_pointer_kind Method >
explicit method_type_data(type_list<Method>);
};

View File

@@ -11,80 +11,28 @@
namespace meta_hpp
{
inline any_type::any_type(data_ptr data)
: data_{data} {}
inline bool any_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline any_type::operator bool() const noexcept {
return is_valid();
}
inline type_id any_type::get_id() const noexcept {
return data_->id;
}
inline type_kind any_type::get_kind() const noexcept {
return data_->kind;
}
inline const metadata_map& any_type::get_metadata() const noexcept {
return data_->metadata;
}
inline any_type::any_type(const array_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const class_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const constructor_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const destructor_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const enum_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const function_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const member_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const method_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const nullptr_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const number_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const pointer_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const reference_type& other) noexcept
: data_{detail::type_access(other)} {}
inline any_type::any_type(const void_type& other) noexcept
: data_{detail::type_access(other)} {}
template < detail::type_family Type >
any_type::any_type(const Type& other) noexcept
: any_type{detail::type_access(other)} {}
template < detail::type_family Type >
bool any_type::is() const noexcept {
if constexpr ( std::is_same_v<Type, any_type> ) {
return data_ != nullptr;
} else {
return data_ != nullptr && data_->kind == Type::kind;
constexpr type_kind is_kind{detail::type_traits<Type>::kind};
return data_ != nullptr && data_->kind == is_kind;
}
}
template < detail::type_family Type >
Type any_type::as() const noexcept {
return is<Type>() ? Type{static_cast<typename Type::data_ptr>(data_)} : Type{};
if constexpr ( std::is_same_v<Type, any_type> ) {
return *this;
} else {
using as_data_ptr = typename detail::type_traits<Type>::data_ptr;
return is<Type>() ? Type{static_cast<as_data_ptr>(data_)} : Type{};
}
}
inline bool any_type::is_array() const noexcept {

View File

@@ -27,29 +27,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline array_type::array_type(data_ptr data)
: data_{data} {}
inline bool array_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline array_type::operator bool() const noexcept {
return is_valid();
}
inline type_id array_type::get_id() const noexcept {
return data_->id;
}
inline array_bitflags array_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& array_type::get_metadata() const noexcept {
return data_->metadata;
}
inline std::size_t array_type::get_extent() const noexcept {
return data_->extent;
}

View File

@@ -34,29 +34,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline class_type::class_type(data_ptr data)
: data_{data} {}
inline bool class_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline class_type::operator bool() const noexcept {
return is_valid();
}
inline type_id class_type::get_id() const noexcept {
return data_->id;
}
inline class_bitflags class_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& class_type::get_metadata() const noexcept {
return data_->metadata;
}
inline std::size_t class_type::get_size() const noexcept {
return data_->size;
}

View File

@@ -27,29 +27,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline constructor_type::constructor_type(data_ptr data)
: data_{data} {}
inline bool constructor_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline constructor_type::operator bool() const noexcept {
return is_valid();
}
inline type_id constructor_type::get_id() const noexcept {
return data_->id;
}
inline constructor_bitflags constructor_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& constructor_type::get_metadata() const noexcept {
return data_->metadata;
}
inline std::size_t constructor_type::get_arity() const noexcept {
return data_->argument_types.size();
}

View File

@@ -26,29 +26,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline destructor_type::destructor_type(data_ptr data)
: data_{data} {}
inline bool destructor_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline destructor_type::operator bool() const noexcept {
return is_valid();
}
inline type_id destructor_type::get_id() const noexcept {
return data_->id;
}
inline destructor_bitflags destructor_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& destructor_type::get_metadata() const noexcept {
return data_->metadata;
}
inline class_type destructor_type::get_owner_type() const noexcept {
return data_->owner_type;
}

View File

@@ -29,29 +29,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline enum_type::enum_type(data_ptr data)
: data_{data} {}
inline bool enum_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline enum_type::operator bool() const noexcept {
return is_valid();
}
inline type_id enum_type::get_id() const noexcept {
return data_->id;
}
inline enum_bitflags enum_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& enum_type::get_metadata() const noexcept {
return data_->metadata;
}
inline number_type enum_type::get_underlying_type() const noexcept {
return data_->underlying_type;
}

View File

@@ -14,10 +14,10 @@
namespace meta_hpp::detail
{
template < function_kind Function >
template < function_pointer_kind Function >
struct function_tag {};
template < function_kind Function >
template < function_pointer_kind Function >
function_type_data::function_type_data(type_list<Function>)
: type_data_base{type_id{type_list<function_tag<Function>>{}}, type_kind::function_}
, flags{function_traits<Function>::make_flags()}
@@ -27,29 +27,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline function_type::function_type(data_ptr data)
: data_{data} {}
inline bool function_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline function_type::operator bool() const noexcept {
return is_valid();
}
inline type_id function_type::get_id() const noexcept {
return data_->id;
}
inline function_bitflags function_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& function_type::get_metadata() const noexcept {
return data_->metadata;
}
inline std::size_t function_type::get_arity() const noexcept {
return data_->argument_types.size();
}

View File

@@ -14,10 +14,10 @@
namespace meta_hpp::detail
{
template < member_kind Member >
template < member_pointer_kind Member >
struct member_tag {};
template < member_kind Member >
template < member_pointer_kind Member >
member_type_data::member_type_data(type_list<Member>)
: type_data_base{type_id{type_list<member_tag<Member>>{}}, type_kind::member_}
, flags{member_traits<Member>::make_flags()}
@@ -27,29 +27,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline member_type::member_type(data_ptr data)
: data_{data} {}
inline bool member_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline member_type::operator bool() const noexcept {
return is_valid();
}
inline type_id member_type::get_id() const noexcept {
return data_->id;
}
inline member_bitflags member_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& member_type::get_metadata() const noexcept {
return data_->metadata;
}
inline class_type member_type::get_owner_type() const noexcept {
return data_->owner_type;
}

View File

@@ -14,10 +14,10 @@
namespace meta_hpp::detail
{
template < method_kind Method >
template < method_pointer_kind Method >
struct method_tag {};
template < method_kind Method >
template < method_pointer_kind Method >
method_type_data::method_type_data(type_list<Method>)
: type_data_base{type_id{type_list<method_tag<Method>>{}}, type_kind::method_}
, flags{method_traits<Method>::make_flags()}
@@ -28,29 +28,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline method_type::method_type(data_ptr data)
: data_{data} {}
inline bool method_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline method_type::operator bool() const noexcept {
return is_valid();
}
inline type_id method_type::get_id() const noexcept {
return data_->id;
}
inline method_bitflags method_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& method_type::get_metadata() const noexcept {
return data_->metadata;
}
inline std::size_t method_type::get_arity() const noexcept {
return data_->argument_types.size();
}

View File

@@ -19,25 +19,3 @@ namespace meta_hpp::detail
nullptr_type_data::nullptr_type_data(type_list<Nullptr>)
: type_data_base{type_id{type_list<nullptr_tag<Nullptr>>{}}, type_kind::nullptr_} {}
}
namespace meta_hpp
{
inline nullptr_type::nullptr_type(data_ptr data)
: data_{data} {}
inline bool nullptr_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline nullptr_type::operator bool() const noexcept {
return is_valid();
}
inline type_id nullptr_type::get_id() const noexcept {
return data_->id;
}
inline const metadata_map& nullptr_type::get_metadata() const noexcept {
return data_->metadata;
}
}

View File

@@ -27,29 +27,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline number_type::number_type(data_ptr data)
: data_{data} {}
inline bool number_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline number_type::operator bool() const noexcept {
return is_valid();
}
inline type_id number_type::get_id() const noexcept {
return data_->id;
}
inline number_bitflags number_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& number_type::get_metadata() const noexcept {
return data_->metadata;
}
inline std::size_t number_type::get_size() const noexcept {
return data_->size;
}

View File

@@ -26,29 +26,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline pointer_type::pointer_type(data_ptr data)
: data_{data} {}
inline bool pointer_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline pointer_type::operator bool() const noexcept {
return is_valid();
}
inline type_id pointer_type::get_id() const noexcept {
return data_->id;
}
inline pointer_bitflags pointer_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& pointer_type::get_metadata() const noexcept {
return data_->metadata;
}
inline any_type pointer_type::get_data_type() const noexcept {
return data_->data_type;
}

View File

@@ -26,29 +26,10 @@ namespace meta_hpp::detail
namespace meta_hpp
{
inline reference_type::reference_type(data_ptr data)
: data_{data} {}
inline bool reference_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline reference_type::operator bool() const noexcept {
return is_valid();
}
inline type_id reference_type::get_id() const noexcept {
return data_->id;
}
inline reference_bitflags reference_type::get_flags() const noexcept {
return data_->flags;
}
inline const metadata_map& reference_type::get_metadata() const noexcept {
return data_->metadata;
}
inline any_type reference_type::get_data_type() const noexcept {
return data_->data_type;
}

View File

@@ -19,25 +19,3 @@ namespace meta_hpp::detail
void_type_data::void_type_data(type_list<Void>)
: type_data_base{type_id{type_list<void_tag<Void>>{}}, type_kind::void_} {}
}
namespace meta_hpp
{
inline void_type::void_type(data_ptr data)
: data_{data} {}
inline bool void_type::is_valid() const noexcept {
return data_ != nullptr;
}
inline void_type::operator bool() const noexcept {
return is_valid();
}
inline type_id void_type::get_id() const noexcept {
return data_->id;
}
inline const metadata_map& void_type::get_metadata() const noexcept {
return data_->metadata;
}
}

View File

@@ -76,7 +76,7 @@ namespace meta_hpp
void reset();
void swap(uvalue& other) noexcept;
[[nodiscard]] const any_type& get_type() const noexcept;
[[nodiscard]] any_type get_type() const noexcept;
[[nodiscard]] void* get_data() noexcept;
[[nodiscard]] const void* get_data() const noexcept;

View File

@@ -72,7 +72,7 @@ namespace meta_hpp
template < typename T, typename... Args, typename Tp = std::decay_t<T> >
static Tp& do_ctor(uvalue& dst, Args&&... args) {
assert(!dst); // NOLINT
META_HPP_ASSERT(!dst);
if constexpr ( in_internal_v<Tp> ) {
std::construct_at(storage_cast<Tp>(dst.storage_), std::forward<Args>(args)...);
@@ -90,7 +90,7 @@ namespace meta_hpp
}
static void do_move(uvalue&& self, uvalue& to) noexcept {
assert(!to); // NOLINT
META_HPP_ASSERT(!to);
auto&& [tag, vtable] = unpack_vtag(self);
@@ -109,7 +109,7 @@ namespace meta_hpp
}
static void do_copy(const uvalue& self, uvalue& to) noexcept {
assert(!to); // NOLINT
META_HPP_ASSERT(!to);
auto&& [tag, vtable] = unpack_vtag(self);
@@ -171,7 +171,8 @@ namespace meta_hpp
.type = resolve_type<Tp>(),
.move{[](uvalue&& self, uvalue& to) noexcept {
assert(self && !to); // NOLINT
META_HPP_ASSERT(!to);
META_HPP_ASSERT(self);
Tp* src = storage_cast<Tp>(self.storage_);
@@ -186,7 +187,8 @@ namespace meta_hpp
}},
.copy{[](const uvalue& self, uvalue& to) {
assert(self && !to); // NOLINT
META_HPP_ASSERT(!to);
META_HPP_ASSERT(self);
const Tp* src = storage_cast<Tp>(self.storage_);
@@ -200,7 +202,7 @@ namespace meta_hpp
}},
.reset{[](uvalue& self) noexcept {
assert(self); // NOLINT
META_HPP_ASSERT(self);
Tp* src = storage_cast<Tp>(self.storage_);
@@ -345,10 +347,9 @@ namespace meta_hpp
vtable_t::do_swap(*this, other);
}
inline const any_type& uvalue::get_type() const noexcept {
static any_type void_type = resolve_type<void>();
inline any_type uvalue::get_type() const noexcept {
auto&& [tag, vtable] = vtable_t::unpack_vtag(*this);
return tag == storage_e::nothing ? void_type : vtable->type;
return tag == storage_e::nothing ? any_type{} : vtable->type;
}
inline void* uvalue::get_data() noexcept {
@@ -364,7 +365,7 @@ namespace meta_hpp
return storage_.external.ptr;
}
assert(false); // NOLINT
META_HPP_ASSERT(false);
return nullptr;
}
@@ -381,7 +382,7 @@ namespace meta_hpp
return storage_.external.ptr;
}
assert(false); // NOLINT
META_HPP_ASSERT(false);
return nullptr;
}
@@ -398,7 +399,7 @@ namespace meta_hpp
return storage_.external.ptr;
}
assert(false); // NOLINT
META_HPP_ASSERT(false);
return nullptr;
}
@@ -452,7 +453,7 @@ namespace meta_hpp
}
}
META_HPP_THROW_AS(exception, "bad value cast");
META_HPP_THROW("bad value cast");
}
template < typename T >
@@ -469,7 +470,7 @@ namespace meta_hpp
}
}
META_HPP_THROW_AS(exception, "bad value cast");
META_HPP_THROW("bad value cast");
}
template < typename T >
@@ -486,7 +487,7 @@ namespace meta_hpp
}
}
META_HPP_THROW_AS(exception, "bad value cast");
META_HPP_THROW("bad value cast");
}
template < typename T >