I recently came across an old C-function returning a pointer to an static array. I wrote a wrapper around that function and returned a std::unique_ptr
that uses a no-delete to emphasize the type of pointer being returned - a "don't delete me" warning to the user. Here is a sample code
extern "C" int *f(int i);
struct noop
{
template <typename T>
void operator() (T t) const noexcept
{
}
};
class MyClass
{
public:
std::unique_ptr<int, noop> F(int value) const
{
return std::unique_ptr<int, noop>(f(value));
}
};
Is there a cleaner way of doing this without defining a no-delete struct?