This is not a hack, this is a completely valid use of forward declarations to avoid some dependency like boost to leak into other parts of the project, like the dictionary generation.
Just be careful to forward declare correctly. The boost::asio::io_context
is not a class but a struct. But you wrap it in your own Context
struct anyway, which you then forward declare! This is very good, because then you have full control if forward declaration and actual declaration are matching.
Also, another tool that might come handy is the __CLING__
preprocessor macro, which is only defined when you use the interpreter Cling (like in the dictionary generation where you’re getting the error). So you can do maybe something like:
#ifndef __CLING__
// when using Cling, forward declare "Context"
// to avoid indirect inclusion of boost/asio header
namespace MWE {
struct Context;
}
#else
// otherwise, include full header for convenience
// (maybe this is not even adding convenience in any case,
// then just forget about this preprocessor conditionals).
#include <context.hpp>
#endif