-
Notifications
You must be signed in to change notification settings - Fork 505
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
SQLite::INTEGER, SQLite::FLOAT,... not declared constexpr
#302
Labels
Comments
Hello, thanks for the suggestion. |
You could do something like this: diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h
index 8fee096..a524e95 100644
--- a/include/SQLiteCpp/Column.h
+++ b/include/SQLiteCpp/Column.h
@@ -22,11 +22,11 @@ struct sqlite3_stmt;
namespace SQLite
{
-extern const int INTEGER; ///< SQLITE_INTEGER
-extern const int FLOAT; ///< SQLITE_FLOAT
-extern const int TEXT; ///< SQLITE_TEXT
-extern const int BLOB; ///< SQLITE_BLOB
-extern const int Null; ///< SQLITE_NULL
+constexpr int INTEGER = 1; ///< SQLITE_INTEGER
+constexpr int FLOAT = 2; ///< SQLITE_FLOAT
+constexpr int TEXT = 3; ///< SQLITE_TEXT
+constexpr int BLOB = 4; ///< SQLITE_BLOB
+constexpr int Null = 5; ///< SQLITE_NULL
/**
* @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement.
diff --git a/src/Column.cpp b/src/Column.cpp
index 60b3c3b..da80bf5 100644
--- a/src/Column.cpp
+++ b/src/Column.cpp
@@ -18,11 +18,11 @@
namespace SQLite
{
-const int INTEGER = SQLITE_INTEGER;
-const int FLOAT = SQLITE_FLOAT;
-const int TEXT = SQLITE_TEXT;
-const int BLOB = SQLITE_BLOB;
-const int Null = SQLITE_NULL;
+static_assert(INTEGER == SQLITE_INTEGER, "SQLITE_INTEGER is no longer 1");
+static_assert(FLOAT == SQLITE_FLOAT, "SQLITE_FLOAT is no longer 2");
+static_assert(TEXT == SQLITE_TEXT, "SQLITE_TEXT is no longer 3");
+static_assert(BLOB == SQLITE_BLOB, "SQLITE_BLOB is no longer 4");
+static_assert(Null == SQLITE_NULL, "SQLITE_NULL is no longer 5");
// Encapsulation of a Column in a row of the result pointed by the prepared Statement. The only downside is I think it will affect binary compatibility. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The declaration of those constants currently looks like this:
This renders them unusable in contexts that require a constant expression, such as a
switch
statements. Declaring themconstexpr
and assigning a value inside the header should fix this.The text was updated successfully, but these errors were encountered: