Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement move constructors #190

Closed
bstaletic opened this issue Mar 3, 2019 · 3 comments
Closed

Implement move constructors #190

bstaletic opened this issue Mar 3, 2019 · 3 comments
Assignees

Comments

@bstaletic
Copy link

Things like Database and Statement leverage RAII and own some kind of object, so it makes sense to make them non-copyable. However moving them around should be supported.
Consider the following:

class DatabaseWrapper {
        SQLite::Database db;
        SQLite::Statement query;
public:
        DatabaseWrapper() : 
            db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE)
            // The following line doesn't work - "Table" still doesn't exist
            // , query(db, "select * from Table where X = ?")
        {
                SQLite::Transaction tr(db);
                db.exec("create table Table (X varchar)");
                tr.commit();
                // Can't use copy assignment to innitialize `query`
                // query = SQLite::Statement(db, "select * from Table where X = ?");
                // No move constructor provided
                // query = std::move( SQLite::Statement(db, "select * from Table where X = ?") );
        }
};

I was trying to use this to save time constructing the Statement in a tight loop.

@SRombauts
Copy link
Owner

Yes, it totally make sense!

At the beginning of the project I was using VS2010 Pre C++11 but now I could even make a V2 full C++11 kwas always the plan)

@SRombauts SRombauts self-assigned this Mar 3, 2019
@SRombauts
Copy link
Owner

Also, Database received a move ctor recently :)

@SRombauts
Copy link
Owner

Ok, so the first thing to note is that the Database move ctor introduced in #157 is guarded by #if __cplusplus >= 201103L, which sadly does not work with Visual Studio.

Second thing is there is no unit tests nor examples to this.

I'll work to improve this asap, and then complete other classes with such move semantics as appropriate.

SRombauts added a commit that referenced this issue Mar 3, 2019
Added checks to proper _MSC_VER 1600 (VS2010)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants