fix some potential problem in the type_registry::for_each_type function

This commit is contained in:
BlackMATov
2023-12-29 23:31:22 +07:00
parent f248035c30
commit e2b295784b
4 changed files with 11 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ namespace meta_hpp::detail
void for_each_scope(F&& f) const {
const locker lock;
for ( auto&& [name, scope] : scopes_ ) {
for ( auto&& [_, scope] : scopes_ ) {
std::invoke(f, scope);
}
}

View File

@@ -41,8 +41,10 @@ namespace meta_hpp::detail
void for_each_type(F&& f) const {
const locker lock;
for ( const any_type& type : types_ ) {
std::invoke(f, type);
// we use an index based for loop to avoid the iterator invalidation issues
// that can happen when adding a new type inside the loop
for ( std::size_t i{}; i < types_.size(); ++i ) {
std::invoke(f, types_[i]);
}
}