template
static const Metatype* get_metatype() {
static const Metatype* mt = []() {
constexpr size_t name_hash = Metatype::build_hash().name_hash;
auto type = metatype_cache.find(name_hash);
if (type == metatype_cache.end()) {
constexpr Metatype newtype = Metatype::build();
metatype_cache[name_hash] = newtype;
}
return &metatype_cache[name_hash];
}();
return mt;
}
< /code>
variable mt < /em> инициализирован с помощью возвращаемого значения Lambda. Почему бы просто не извлечь код Lambda и не сделать его частью функции get_metatype (), а затем просто вернуть его значение? Это какой -то трюк или что ??
Этот код из Decs https://github.com/vblanco20-1/decs, который я изучаю в образовательных целях.
Подробнее здесь: https://stackoverflow.com/questions/611 ... ation-to-i
Мобильная версия