1

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?

John Bartholomew
  • 6,428
  • 1
  • 30
  • 39

1 Answers1

2

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.

Joaquín M López Muñoz
  • 5,243
  • 1
  • 15
  • 20