Skip to content

Commit d93c90e

Browse files
committed
Allow falling back to boost charconv
1 parent 771f723 commit d93c90e

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

expr2/exprfilter.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define USE_EXPR_CACHE
2121

2222
#include <algorithm>
23-
#include <charconv>
2423
#include <cmath>
2524
#include <cctype>
2625
#include <clocale>
@@ -45,6 +44,18 @@
4544
#include "Module.hpp"
4645
#include "Debug.hpp"
4746

47+
#ifdef USE_BOOST_CHARCONV
48+
49+
#include <boost/charconv.hpp>
50+
using boost::charconv::from_chars;
51+
52+
#else
53+
54+
#include <charconv>
55+
using std::from_chars;
56+
57+
#endif
58+
4859
namespace {
4960

5061
#define LANES 8
@@ -288,7 +299,7 @@ ExprOp decodeToken(const std::string &token, bool extended = false)
288299
return name[0] >= 'x' ? name[0] - 'x' : name[0] - 'a' + 3;
289300
int idx = -1;
290301

291-
auto result = std::from_chars(name.c_str() + clipNamePrefix.size(), name.c_str() + name.length(), idx);
302+
auto result = from_chars(name.c_str() + clipNamePrefix.size(), name.c_str() + name.length(), idx);
292303
if (result.ec != std::errc()) {
293304
throw std::runtime_error("invalid clip name: " + name);
294305
}
@@ -309,7 +320,7 @@ ExprOp decodeToken(const std::string &token, bool extended = false)
309320
size_t prefix = token[1] == 'u' ? 3 : 4;
310321
int idx = -1;
311322

312-
auto result = std::from_chars(token.c_str() + prefix, token.c_str() + token.length(), idx);
323+
auto result = from_chars(token.c_str() + prefix, token.c_str() + token.length(), idx);
313324
if (result.ec != std::errc()) {
314325
// ...
315326
}
@@ -330,7 +341,7 @@ ExprOp decodeToken(const std::string &token, bool extended = false)
330341
size_t prefix = token[3] == 's' ? 7 : 6;
331342
int idx = -1;
332343

333-
auto result = std::from_chars(token.c_str() + prefix, token.c_str() + token.length(), idx);
344+
auto result = from_chars(token.c_str() + prefix, token.c_str() + token.length(), idx);
334345
if (result.ec != std::errc()) {
335346
// ...
336347
}
@@ -366,7 +377,7 @@ ExprOp decodeToken(const std::string &token, bool extended = false)
366377
float f = 0;
367378
const size_t len = token.size();
368379

369-
auto resultl = std::from_chars(token.c_str(), token.c_str() + len, l, 0);
380+
auto resultl = from_chars(token.c_str(), token.c_str() + len, l, 0);
370381
if (resultl.ec == std::errc()) {
371382
pos = std::distance(token.c_str(), resultl.ptr);
372383
}
@@ -377,7 +388,7 @@ ExprOp decodeToken(const std::string &token, bool extended = false)
377388
return { ExprOpType::CONSTANTF, (float)l };
378389
}
379390

380-
auto resultf = std::from_chars(token.c_str(), token.c_str() + len, f);
391+
auto resultf = from_chars(token.c_str(), token.c_str() + len, f);
381392
if (resultf.ec == std::errc()) {
382393
pos = std::distance(token.c_str(), resultf.ptr);
383394
}

meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ version_h = declare_dependency(
1515
is_windows = target_machine.system() == 'windows' or target_machine.system() == 'cygwin'
1616
use_asmjit = get_option('asmjit')
1717
static_llvm = get_option('static-llvm')
18+
boost_charconv = get_option('boost-charconv')
1819

1920
sources_expr = [
2021
# expr
@@ -98,6 +99,11 @@ else
9899
endif
99100
endif
100101

102+
if boost_charconv
103+
add_project_arguments('-DUSE_BOOST_CHARCONV', language: 'cpp')
104+
deps += dependency('boost', modules: ['charconv'], static: get_option('prefer_static')) #
105+
endif
106+
101107
libs = []
102108

103109
if is_windows

meson_options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ option('asmjit', type: 'boolean', value: false,
33

44
option('static-llvm', type: 'boolean', value: true,
55
description: 'Whether to statically link LLVM')
6+
7+
option('boost-charconv', type: 'boolean', value: false,
8+
description: 'Whether to use boost\'s charconv')

0 commit comments

Comments
 (0)