This is what I would like to get. The caller does not have access to B namespace.
template<typename T>
A::T foo1(std::vector<std::uint8_t> const& data)
{
return foo2<B::T>(data);
}
T is a type defined (in different ways) both in A and B. I tried to solve this problem but the only solution that seems feasible is to overload it like this:
void foo1(A::typeX& out, std::vector<std::uint8_t> const& data)
{
out = foo2<B::typeX>(data);
}
void foo1(A::typeY& out, std::vector<std::uint8_t> const& data)
{
out = foo2<B::typeY>(data);
}
It is a good solution but it requires a new function to be added every time a new type (say typeZ) needs to be handled (notice that passing the out parameter as a reference is the only way to overload it as I cannot make the overloaded functions return it directly since they would differ only for the returned type, and this is not permitted). Again, the caller only knows about A namespace, so it cannot call foo2() directly.
The standard of C++ I'm using is C++14 (experimental namespaces allowed)
I hope I,ve been clear enough. Thank you!
I tried to map the input/output type but I didn't end up with a working solution and neither me neither the rest of the team liked that.
I'm expecting to find a workaround to make the first code snippet working (of course, not exactly in the way I wrote it). In general, I'm trying to specialise a namespace: if the input parameter type is A::typeX then I use the B::typeX namespace, otherwise if the input parameter type is A::typeY then I use the B::typeY namespace.
Preferably (notice, preferably) I'd like a solution that doesn't require predefined mappings.
The only way to do this AFAIK is to use some kind of type map, either by using
std::conditionalor template specialization.And then use the map in the functions
If the types in
Bare identical to the types inAthen you can import the types intoAinstead of defining identical structs.