Reply to post: Re: Well...

helloSystem: Pre-alpha FreeBSD project chases simplicity and elegance by taking cues from macOS

sed gawk Silver badge

Re: Well...

If you wrap everything using std::unique_ptr with custom deleter, it's a lot less painful to wrap the underlying C libraries.

For MySQL (don't ask)

namespace std

{

template <>

class default_delete< MYSQL >

{

public:

void

operator()(MYSQL *ptr)

{

mysql_close(ptr);

}

};

template <>

class default_delete< MYSQL_RES >

{

public:

void

operator()(MYSQL_RES *ptr)

{

mysql_free_result(ptr);

}

};

} // namespace std

...

std::unique_ptr< MYSQL_RES > sql;

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2021