query/include/matador/sql/foreign.hpp

34 lines
640 B
C++

#ifndef QUERY_FOREIGN_HPP
#define QUERY_FOREIGN_HPP
#include <memory>
namespace matador::sql {
template < class Type >
class foreign
{
public:
foreign() = default;
explicit foreign(Type *obj)
: obj_(obj) {}
Type* operator->() { return obj_.get(); }
const Type* operator->() const { return obj_.get(); }
Type& operator*() { return *obj_; }
const Type& operator*() const { return *obj_; }
private:
std::unique_ptr<Type> obj_;
};
template<class Type, typename... Args>
[[maybe_unused]] foreign<Type> make_foreign(Args&&... args)
{
return foreign(new Type(std::forward<Args>(args)...));
}
}
#endif //QUERY_FOREIGN_HPP