Skip to content

Commit

Permalink
Add SCN_CONSTEXPRIF
Browse files Browse the repository at this point in the history
  • Loading branch information
matbech authored and eliaskosunen committed Nov 2, 2023
1 parent f27930c commit 7e8007a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions include/scn/detail/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@
#define SCN_CONSTEXPR14 inline
#endif


// Detect if constexpr
#if (defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606) || \
((SCN_MSVC >= SCN_COMPILER(19, 11, 0) && SCN_MSVC_LANG >= SCN_STD_17))
#define SCN_CONSTEXPRIF constexpr
#else
#define SCN_CONSTEXPRIF
#endif

// Detect string_view
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201603 && \
SCN_STD >= SCN_STD_17
Expand Down
8 changes: 4 additions & 4 deletions src/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace scn {
span<const char_type> ch) const
{
const auto& locale = to_locale(*this);
if (sizeof(CharT) == 1) {
if SCN_CONSTEXPRIF (sizeof(CharT) == 1) {
SCN_EXPECT(ch.size() >= 1);
code_point cp{};
auto it = parse_code_point(ch.begin(), ch.end(), cp);
Expand All @@ -271,7 +271,7 @@ namespace scn {
span<const char_type> ch) const
{
const auto& locale = to_locale(*this);
if (sizeof(CharT) == 1) {
if SCN_CONSTEXPRIF (sizeof(CharT) == 1) {
SCN_EXPECT(ch.size() >= 1);
code_point cp{};
auto it = parse_code_point(ch.begin(), ch.end(), cp);
Expand All @@ -298,7 +298,7 @@ namespace scn {
const \
{ \
const auto& locale = to_locale(*this); \
if (sizeof(CharT) == 1) { \
if SCN_CONSTEXPRIF (sizeof(CharT) == 1) { \
SCN_EXPECT(ch.size() >= 1); \
code_point cp{}; \
auto it = parse_code_point(ch.begin(), ch.end(), cp); \
Expand Down Expand Up @@ -348,7 +348,7 @@ namespace scn {
span<const char_type> ch) const
{
const auto& locale = to_locale(*this);
if (sizeof(CharT) == 1) {
if SCN_CONSTEXPRIF (sizeof(CharT) == 1) {
SCN_EXPECT(ch.size() >= 1);
code_point cp{};
auto it = parse_code_point(ch.begin(), ch.end(), cp);
Expand Down

0 comments on commit 7e8007a

Please sign in to comment.