Replies: 1 comment 4 replies
-
Thanks for the simple example and test case. This is not the simplest feature to support. We would need to deduce what types your nested variant could support. We would have to start off making this code handle nested variants: template <typename>
struct variant_types;
template <typename... Ts>
struct variant_types<std::variant<Ts...>>
{
// TODO this way of filtering types is compile time intensive.
using bool_types = decltype(tuplet::tuple_cat(
std::conditional_t<bool_t<remove_meta_wrapper_t<Ts>>, tuplet::tuple<Ts>, tuplet::tuple<>>{}...));
using number_types = decltype(tuplet::tuple_cat(
std::conditional_t<num_t<remove_meta_wrapper_t<Ts>>, tuplet::tuple<Ts>, tuplet::tuple<>>{}...));
using string_types = decltype(tuplet::tuple_cat( // glaze_enum_t remove_meta_wrapper_t supports constexpr types
// while the other supports non const
std::conditional_t < str_t<remove_meta_wrapper_t<Ts>> || glaze_enum_t<remove_meta_wrapper_t<Ts>> ||
glaze_enum_t<Ts>,
tuplet::tuple<Ts>, tuplet::tuple < >> {}...));
using object_types = decltype(tuplet::tuple_cat(
std::conditional_t < reflectable<Ts> || readable_map_t<Ts> || writable_map_t<Ts> || glaze_object_t<Ts>,
tuplet::tuple<Ts>, tuplet::tuple < >> {}...));
using array_types =
decltype(tuplet::tuple_cat(std::conditional_t < array_t<remove_meta_wrapper_t<Ts>> || glaze_array_t<Ts>,
tuplet::tuple<Ts>, tuplet::tuple < >> {}...));
using nullable_types =
decltype(tuplet::tuple_cat(std::conditional_t<null_t<Ts>, tuplet::tuple<Ts>, tuplet::tuple<>>{}...));
}; However, even if we added support to handle nested variants, your type still fails to be auto-deducible (see variant documentation). This is because your top level variant supports both I'm a bit surprised you can't just have a single variant of all these types for your use case. Can you give some insight into why this nested variant approach is useful to you? I'm interested in this problem, but it is a bit complex and we'll need to understand the motivation well to come up with a good solution. |
Beta Was this translation helpful? Give feedback.
-
I am having some issues parsing a json structure into std::variant defined within a std::variant.
I have created a basic failing std::variant test that is valid code and should work. But is not exactly my structure.
It seems there are not problems encoing the value of data:
Parsing the string into this particular type yields this result
Beta Was this translation helpful? Give feedback.
All reactions