Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add session::get_backend<BackendImpl>() cast #220

mloskot opened this Issue Nov 12, 2013 · 2 comments


None yet
2 participants

mloskot commented Nov 12, 2013

Let's free users from ugly cast (example below from this thread):

soci::sqlite3_session_backend * sessionBackEnd =
   static_cast<soci::sqlite3_session_backend *>(sql.get_backend());
sqlite_api::sqlite3_busy_timeout(sessionBackEnd->conn_, 1000);

with a tiny template function

class session {
  template <typename BackendImpl>
  BackendImpl* get_backend()
     return static_cast<BackendImpl*>(get_backend());

Instead of using actual BackendImpl (i.e. soci::sqlite3_session_backend) directly, we could dispatch based on backend-specific tag:


vadz commented Nov 12, 2013

Ideal would be to make this function safe, at least at run-time, i.e. return NULL if the backend is not actually of the right type, otherwise you'd have an illusion of safe code (as the cast is hidden inside the library) but without the real safety.


mloskot commented Nov 12, 2013

@vadz Yes, some sort of dynamic/lexical_cast semantic is desirable.

The codes I posted above are considered to be a bit of sketch-up, not actual implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment