@@ -71,11 +71,11 @@ class serialize_impl<std::variant<Types...>>
7171 // single "type" template argument. This specialization matches std::index_sequence<INDEX...> representing a
7272 // sequence of subscripts 0, 1, 2, ..., sizeof...(Types)-1 generated by std::index_sequence_for<Types...>
7373 //
74- // This set_index partial specialization has a constexpr array of function pointers initialized by a list of lambda
75- // expressions, each of which takes a std::variant<Types...>& obj argument and calls obj.emplace<INDEX>() which
76- // changes the active variant of obj to the Types... entry corresponding to INDEX. The emplace<INDEX>() method is
77- // called with no constructor arguments, which means that the new active variant will be default-constructed. This
78- // changing of the active variant happens before the new variant is deserialized in-place.
74+ // This set_index partial specialization has a constexpr array of function pointers, each of which takes a
75+ // std::variant<Types...>& obj argument and calls obj.emplace<INDEX>() which changes the active variant of obj to
76+ // the Types... entry corresponding to INDEX. The emplace<INDEX>() method is called with no constructor arguments,
77+ // which means that the new active variant will be default-constructed. This changing of the active variant happens
78+ // before the new variant is deserialized in-place.
7979 //
8080 // Although std::visit can invoke a function with the currently active std::variant, it relies on knowing the
8181 // currently active variant as returned by index(). To CHANGE the currently active variant requires an assignment
@@ -91,11 +91,17 @@ class serialize_impl<std::variant<Types...>>
9191 template <typename >
9292 struct set_index ;
9393
94+ template <size_t INDEX>
95+ static void set_index_func (std::variant<Types...>& obj)
96+ {
97+ obj.template emplace <INDEX>();
98+ }
99+
94100 template <size_t ... INDEX>
95101 struct set_index <std::index_sequence<INDEX...>>
96102 {
97103 static constexpr std::array<void (*)(std::variant<Types...>& obj), sizeof ...(INDEX)> array = {
98- [](std::variant<Types...>& obj) { obj. template emplace < INDEX>(); } ...
104+ set_index_func< INDEX>...
99105 };
100106 };
101107
0 commit comments