I need to support a new type (OuterType
) for libpqxx. This type is located in namespace partner
, also namespace
contains free function to_string(const OuterType&)
, which returns wrapper around fixed size array, which is not convertible to std::string
. Type is maintained by partner and is not editable.
namespace partner {
class OuterType
{
// ...
};
fixed_size_array_wrapper to_string(const OuterType&);
}
I wrote all string_traits for libpqxx, but it's not used during compilation, because libpqxx code looks like:
using entry = std::variant<std::nullptr_t, zview, std::string, bytes_view, bytes>;
...
params.emplace_back(entry{to_string(value)});
Where type of value
is partner::OuterType
. Compiler sees function partner::to_string
by using ADL. How to force compiler to not use partner::to_string
?
Currently I've wrapped OuterType in my own type. It looks like that's the only option.
There is no doubt that main problem is none standard return type of:
fixed_size_array_wrapper to_string(const OuterType&);
Since you do not control this code and code (libpqxx
) where ADL is used the only way to resolve this issue is to isolate both libraries form each other.
IMO simplest way is to add an extra own type which will wrap problematic type:
namespace wrapper {
class OuterType : public ::partner::OuterType {
public:
using OuterType::OuterType;
};
std::string to_string(const OuterType&); // inside of implementation you can do a conversion from fixed_size_array_wrapper to a std::string
}
Then everywhere in your code replace partner::OuterType
with wrapper::OuterType
.
You can also think about completely isolate this partner
code by creating full bridge library which will complete isolate partner
code form other parts of your system (more work, but it will protect you from other problems).