I'm trying to define an immutable file-path value type, taking advantage of boost::flyweight to share path components. Something like this:
struct filepath_data;
typedef boost::flyweight<filepath_data> filepath;
struct filepath_data {
boost::optional<filepath> parent;
std::string name;
};
Of course, this looks like a recursive structure, but boost::flyweight<T>
doesn't actually (itself) contain a copy of T
, just a handle to a T
which can be looked up in the appropriate holder, so I think this structure should work.
Unfortunately, it doesn'开发者_运维知识库t compile, because when g++ hits the typedef it complains that filepath_data is incomplete.
So, the question is, can I make use of the flexibility and more advanced template arguments for boost::flyweight<>
to make this structure work, and if so, how?
This example shows how to combine Boost.Flyweight with a recursive data structure using Boost.Variant and boost::recursive_wrapper
. Maybe you can use a similar approach for your problem.
精彩评论