[info] type_name = "std::optional" ctype = "OPTIONAL_TYPE" header = "optional" # Old: typeName = "std::optional<" ns = ["namespace std"] numTemplateParams = 1 [codegen] decl = """ template void getSizeType(const %1% &container, size_t& returnArg); """ func = """ template void getSizeType(const %1%& container, size_t& returnArg) { if (container) { SAVE_SIZE(sizeof(%1%) - sizeof(T)); SAVE_DATA(true); getSizeType(*container, returnArg); } else { SAVE_SIZE(sizeof(%1%)); SAVE_DATA(false); } } """ handler = """ template struct TypeHandler> { using type = types::st::Sum, typename TypeHandler::type >; static types::st::Unit getSizeType( const %1%& container, typename TypeHandler>::type returnArg) { if (container) { return returnArg.template delegate<1>([&container](auto ret) { return OIInternal::getSizeType(*container, ret); }); } else { return returnArg.template delegate<0>(std::identity()); } } }; """ traversal_func = """ if (container.has_value()) { return returnArg.template delegate<1>([&container](auto ret) { return OIInternal::getSizeType(*container, ret); }); } else { return returnArg.template delegate<0>(std::identity()); } """ [[codegen.processor]] type = "types::st::Sum, typename TypeHandler::type>" func = """ static constexpr std::array names{"TODO"}; static constexpr auto elementField = inst::Field{ sizeof(T0), "el", names, TypeHandler::fields, TypeHandler::processors, }; auto sum = std::get(d.val); el.container_stats = result::Element::ContainerStats { .capacity = 1, .length = sum.index, }; if (sum.index == 1) { el.exclusive_size -= sizeof(T0); stack_ins(elementField); } """