Lets say I have a class Customer in namespace Data. Using boost, I know I can convert this into valid JSON by declaring a function with the signature: void tag_invoke( const value_from_tag&, value& jv, Customer const& c ).
However, in all of the examples in the boost documentation, it appears that this tag_invoke function must reside in the Data namespace, i.e. the same namespace as Customer.
I would like to know if it is possible to have something like the following:
namespace FileIO
{
void tag_invoke( const value_from_tag&, value& jv, Data::Customer const& c );
{
jv = {
{ "id", c.id },
{ "name", c.name },
{ "late", c.late }
};
}
}
namespace Network
{
void tag_invoke( const value_from_tag&, value& jv, Data::Customer const& c )
{
jv = {
{ "id", c.id },
{ "late", c.late }
};
}
}
In other words, have two different implementations of the value conversion, where the current namespace would determine which one gets used. I've not had any success getting it working, being met with various "no matching call to value_from_impl" errors.
In case it helps, my CMake setup is such that Data, FileIO, and Network are all separate targets, where both FileIO and Network are linked to/depend Data, but not to each other, and Data depends on no other libraries.
Any advice would be appreciated