Home > Enterprise >  Recursive typedef definition using std::variant
Recursive typedef definition using std::variant

Time:01-10

I want to define a std::variant that can store a vector of pairs, with strings and Values.

I want to create a structure like below:

typedef std::variant<bool, int, float, std::vector<std::pair<std::string, Value>>> Value;

How can I do it in C 17?

CodePudding user response:

As HolyBlackCat notes in the comments, you need Value to be a type (but it can be incomplete) to use it in the pair.

struct Value
{
    std::variant<bool, int, float, std::vector<std::pair<std::string, Value>>> data;
};

See it on coliru

  • Related