Skip to content

Commit

Permalink
Fixed constexpr lambda only being available with C++17
Browse files Browse the repository at this point in the history
  • Loading branch information
trueqbit committed Nov 17, 2023
1 parent 0eada6a commit 5aaca86
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions dev/functional/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include <version>
#endif

#ifdef SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED
#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 constexpr
#else
#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17
#endif

#ifdef SQLITE_ORM_INLINE_VARIABLES_SUPPORTED
#define SQLITE_ORM_INLINE_VAR inline
#else
Expand Down
4 changes: 4 additions & 0 deletions dev/functional/cxx_core_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#define SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED
#endif

#if __cpp_constexpr >= 201603L
#define SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED
#endif

#if __cpp_if_constexpr >= 201606L
#define SQLITE_ORM_IF_CONSTEXPR_SUPPORTED
#endif
Expand Down
2 changes: 1 addition & 1 deletion dev/udf_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace sqlite_orm {
std::allocator<UDF> allocator;
using traits = std::allocator_traits<decltype(allocator)>;

constexpr auto deallocate = [](void* location) noexcept {
SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept {
std::allocator<UDF> allocator;
using traits = std::allocator_traits<decltype(allocator)>;
traits::deallocate(allocator, (UDF*)location, 1);
Expand Down
12 changes: 11 additions & 1 deletion include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ using std::nullptr_t;
#define SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED
#endif

#if __cpp_constexpr >= 201603L
#define SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED
#endif

#if __cpp_if_constexpr >= 201606L
#define SQLITE_ORM_IF_CONSTEXPR_SUPPORTED
#endif
Expand Down Expand Up @@ -167,6 +171,12 @@ using std::nullptr_t;
#include <version>
#endif

#ifdef SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED
#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 constexpr
#else
#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17
#endif

#ifdef SQLITE_ORM_INLINE_VARIABLES_SUPPORTED
#define SQLITE_ORM_INLINE_VAR inline
#else
Expand Down Expand Up @@ -14885,7 +14895,7 @@ namespace sqlite_orm {
std::allocator<UDF> allocator;
using traits = std::allocator_traits<decltype(allocator)>;

constexpr auto deallocate = [](void* location) noexcept {
SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept {
std::allocator<UDF> allocator;
using traits = std::allocator_traits<decltype(allocator)>;
traits::deallocate(allocator, (UDF*)location, 1);
Expand Down
4 changes: 2 additions & 2 deletions tests/user_defined_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int FirstFunction::objectsCount = 0;
int FirstFunction::callsCount = 0;

#if __cpp_aligned_new >= 201606L
struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) OverAlignedScalarFunction {
struct alignas(2 * __STDCPP_DEFAULT_NEW_ALIGNMENT__) OverAlignedScalarFunction {
int operator()(int arg) const {
return arg;
}
Expand All @@ -181,7 +181,7 @@ struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) OverAlignedScalarFunction {
}
};

struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) OverAlignedAggregateFunction {
struct alignas(2 * __STDCPP_DEFAULT_NEW_ALIGNMENT__) OverAlignedAggregateFunction {
double sum = 0;

void step(double arg) {
Expand Down

0 comments on commit 5aaca86

Please sign in to comment.