I have a RAII wrapper around a Foo*
where Foo
is a library.
The class looks pretty much like this:
struct Handle{
Foo* p;
Handle(): p(foo_new()){}
Handle(Handle&& f): p(std::exchange(f.p, nullptr)){}
Handle(const Handle& f){
p = foo_clone(f.p);
}
};
Error handling and assignment operators omitted for brevity.
The problem now is, that foo_clone
is available in 1 library version, but not an earlier one and the wrapper should support both. There is no *_VERSION
macro for me to check so I need to do it in C++ instead of the preprocessor.
I though of something like:
template<class T, decltype(foo_clone(std::declval<T>().p)) = nullptr>
Handle(const T& f){...}
But this doesnt work: The defined move-ctor requires me to add a copy ctor verbatim as Handle(const Handle&)
, no template trickery seems to be allowed as otherwise the compiler considers the copy-ctor as implicitely deleted.
What can I do?