Skip to content

Commit 0351815

Browse files
tyroguruajor
authored andcommitted
Make folly::Optional TBv2 compliant (#490)
Summary: The container implementation for `folly::Optional` currently lacks TBv2 support. This change is a skilfully crafted cut-n-paste of the `std::optional` TBv2 implementation. Reviewed By: ajor Differential Revision: D56139280
1 parent a014cdd commit 0351815

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

types/folly_optional_type.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,31 @@ void getSizeType(const %1%<T>& container, size_t& returnArg) {
2929
}
3030
}
3131
"""
32+
33+
traversal_func = """
34+
if (container.has_value()) {
35+
return returnArg.template delegate<1>([&ctx, &container](auto ret) {
36+
return OIInternal::getSizeType<Ctx>(ctx, *container, ret);
37+
});
38+
} else {
39+
return returnArg.template delegate<0>(std::identity());
40+
}
41+
"""
42+
43+
[[codegen.processor]]
44+
type = "types::st::Sum<DB, types::st::Unit<DB>, typename TypeHandler<Ctx, T0>::type>"
45+
func = """
46+
static constexpr auto elementField = make_field<Ctx, T0>("el");
47+
48+
auto sum = std::get<ParsedData::Sum>(d.val);
49+
50+
el.container_stats = result::Element::ContainerStats {
51+
.capacity = 1,
52+
.length = sum.index,
53+
};
54+
55+
if (sum.index == 1) {
56+
el.exclusive_size -= sizeof(T0);
57+
stack_ins(elementField);
58+
}
59+
"""

0 commit comments

Comments
 (0)