extend scope function #20

This commit is contained in:
BlackMATov
2023-01-14 17:14:33 +07:00
parent bce3115ff0
commit 4094e234d3
7 changed files with 110 additions and 102 deletions

View File

@@ -8,9 +8,7 @@
#include "meta_base.hpp"
#include "meta_states.hpp"
#include "meta_detail/state_registry.hpp"
#include "meta_detail/type_registry.hpp"
#include "meta_registry.hpp"
namespace meta_hpp::detail
{
@@ -351,11 +349,7 @@ namespace meta_hpp
{
class scope_bind final {
public:
struct local_tag {};
struct static_tag {};
explicit scope_bind(std::string name, metadata_map metadata, local_tag);
explicit scope_bind(std::string_view name, metadata_map metadata, static_tag);
explicit scope_bind(const scope& scope, metadata_map metadata);
operator scope() const noexcept;
// function_
@@ -471,10 +465,16 @@ namespace meta_hpp
namespace meta_hpp
{
inline scope_bind local_scope_(std::string name, metadata_map metadata = {}) {
return scope_bind{std::move(name), std::move(metadata), scope_bind::local_tag()};
scope local_scope{detail::scope_state::make(std::move(name))};
return scope_bind{local_scope, std::move(metadata)};
}
inline scope_bind static_scope_(std::string_view name, metadata_map metadata = {}) {
return scope_bind{name, std::move(metadata), scope_bind::static_tag()};
scope static_scope{resolve_scope(name)};
return scope_bind{static_scope, std::move(metadata)};
}
inline scope_bind extend_scope_(const scope& scope, metadata_map metadata = {}) {
return scope_bind{scope, std::move(metadata)};
}
}

View File

@@ -12,11 +12,8 @@
namespace meta_hpp
{
inline scope_bind::scope_bind(std::string name, metadata_map metadata, local_tag)
: state_{detail::scope_state::make(std::move(name), std::move(metadata))} {}
inline scope_bind::scope_bind(std::string_view name, metadata_map metadata, static_tag)
: state_{detail::state_access(resolve_scope(name))} {
inline scope_bind::scope_bind(const scope& scope, metadata_map metadata)
: state_{detail::state_access(scope)} {
detail::insert_or_assign(state_->metadata, std::move(metadata));
}

View File

@@ -49,7 +49,7 @@ namespace meta_hpp::detail
return iter->second;
}
auto state = scope_state::make(std::string{name}, metadata_map{});
auto state = scope_state::make(std::string{name});
auto&& [iter, _] = scopes_.insert_or_assign(std::string{name}, std::move(state));
return iter->second;
}

View File

@@ -600,7 +600,7 @@ namespace meta_hpp::detail
typedef_map typedefs{};
variable_set variables{};
[[nodiscard]] static scope_state_ptr make(std::string name, metadata_map metadata);
[[nodiscard]] static scope_state_ptr make(std::string name);
};
struct variable_state final {

View File

@@ -19,10 +19,9 @@
namespace meta_hpp::detail
{
inline scope_state_ptr scope_state::make(std::string name, metadata_map metadata) {
inline scope_state_ptr scope_state::make(std::string name) {
return std::make_shared<scope_state>(scope_state{
.index{scope_index::make(std::move(name))},
.metadata{std::move(metadata)},
});
}
}