I've tried defining a variant type for dynamic variables in my program, but I can't seem to be able to make it store a function that returns it as a type.
using Value = std::variant<Integer, Float, Function>;
using Function = std::function<Value()>;
This won't compile because Function needs to be defined at the time Value is, but Function depends on Value too. I've tried fixing this by inlining the Function type into the variant template list but it seems that using statements can't reference themselves or be forward declared.
My best solution so far has been defining Function as a struct so I can forward declare it. This works, but seems so hacky, so I'm wondering if there's a better way?
struct Function;
// define Value
struct Function : std::function<Value()> {};
To clarify, std::function was used as part of the example because I thought it would be easier to show what I was trying to do and it also was needed for my hacky solution. I'd prefer a way to have this working with plain function pointers too, if possible.