I was trying to create a bidirectional tree-like structure, so I`ve ended up with the following structs:
template<typename T>
struct Node
{
T value;
std::vector<Node<T>> kids;
boost::optional<Node<T>> parent { boost::none };
}
template<typename T>
struct Tree
{
std::vector<Node<T>> heads;
};
But when I tried to use such Tree/Node as, for instance, value in unordered_map, I got compilation error (MSVC 17.0, C++ 14):
...boostincludeboost/optional/detail/optional_aligned_storage.hpp(31): error C2027: use of undefined type "Node<std::shared_ptr<Action>>"
After some googling and asking Chat-GPT, it was suggested to replace
boost::optional<Node<T>> parent { boost::none };
with
boost::optional<std::reference_wrapper<Node<T>>> parent { boost::none };
That worked.
However, I honestly have no idea why exactly.
Can anyone explaing that?
Minimal reproducible example on godbolt: click;