movable registry lockers

This commit is contained in:
BlackMATov
2022-12-26 22:14:23 +07:00
parent c61be1017a
commit 266fc027c4
5 changed files with 58 additions and 34 deletions

View File

@@ -13,12 +13,18 @@ namespace meta_hpp::detail
{
class state_registry final {
public:
class locker final : noncopyable {
class locker final {
public:
explicit locker()
: lock_{instance().mutex_} {}
explicit locker() : lock_{instance().mutex_} {}
~locker() = default;
locker(locker&&) = default;
locker& operator=(locker&&) = default;
locker(const locker&) = delete;
locker& operator=(const locker&) = delete;
private:
std::lock_guard<std::recursive_mutex> lock_;
std::unique_lock<std::recursive_mutex> lock_;
};
[[nodiscard]] static state_registry& instance() {

View File

@@ -13,12 +13,18 @@ namespace meta_hpp::detail
{
class type_registry final {
public:
class locker final : noncopyable {
class locker final {
public:
explicit locker()
: lock_{instance().mutex_} {}
explicit locker() : lock_{instance().mutex_} {}
~locker() = default;
locker(locker&&) = default;
locker& operator=(locker&&) = default;
locker(const locker&) = delete;
locker& operator=(const locker&) = delete;
private:
std::lock_guard<std::recursive_mutex> lock_;
std::unique_lock<std::recursive_mutex> lock_;
};
[[nodiscard]] static type_registry& instance() {

View File

@@ -111,9 +111,9 @@ namespace meta_hpp
template < typename... Args >
uvalue class_type::create(Args&&... args) const {
for ( auto&& ctor : data_->constructors ) {
if ( ctor.second.is_invocable_with(std::forward<Args>(args)...) ) {
return ctor.second.invoke(std::forward<Args>(args)...);
for ( auto&& [_, ctor] : data_->constructors ) {
if ( ctor.is_invocable_with(std::forward<Args>(args)...) ) {
return ctor.invoke(std::forward<Args>(args)...);
}
}
return uvalue{};
@@ -126,9 +126,9 @@ namespace meta_hpp
template < typename Arg >
bool class_type::destroy(Arg&& ptr) const {
for ( auto&& dtor : data_->destructors ) {
if ( dtor.second.is_invocable_with(std::forward<Arg>(ptr)) ) {
dtor.second.invoke(std::forward<Arg>(ptr));
for ( auto&& [_, dtor] : data_->destructors ) {
if ( dtor.is_invocable_with(std::forward<Arg>(ptr)) ) {
dtor.invoke(std::forward<Arg>(ptr));
return true;
}
}

View File

@@ -77,9 +77,9 @@ namespace meta_hpp
return std::string_view{};
}
for ( auto&& evalue : data_->evalues ) {
if ( evalue.second.get_value() == value ) {
return evalue.second.get_index().get_name();
for ( auto&& [_, evalue] : data_->evalues ) {
if ( evalue.get_value() == value ) {
return evalue.get_index().get_name();
}
}