mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
fix some potential problem in the type_registry::for_each_type function
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
- fix all includes to work with the library more flexible
|
||||
- test and support shared libraries
|
||||
- add debug type names
|
||||
- auto register destructor without class_<T>
|
||||
|
||||
## Version 1.0
|
||||
|
||||
|
||||
@@ -4050,8 +4050,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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4259,7 +4261,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user