File tree 5 files changed +28
-15
lines changed
5 files changed +28
-15
lines changed Original file line number Diff line number Diff line change 1
1
2
2
cmake_minimum_required (VERSION 3.27)
3
3
4
- project (astr VERSION 0.2.1 LANGUAGES CXX)
4
+ project (astr VERSION 0.3.0 LANGUAGES CXX)
5
5
6
6
if (PROJECT_IS_TOP_LEVEL)
7
7
# make git ignore the build directory
8
8
file (WRITE ${CMAKE_BINARY_DIR} /.gitignore "*" )
9
- set (CMAKE_CXX_STANDARD 20)
10
- set (CMAKE_CXX_EXTENSIONS OFF )
11
- SET (CMAKE_COMPILE_WARNING_AS_ERROR ON ) # turn off with --compile-no-warning-as-error
12
9
set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
13
-
14
10
list (PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR} /cmake" )
15
11
include (setup_compiler)
16
12
include (default_flags)
Original file line number Diff line number Diff line change @@ -23,11 +23,12 @@ endif(NOT isMultiConfig)
23
23
24
24
# Off, we do not want to annoy potential packager
25
25
# option(WARN_ERROR "Thread warnings as errors. Default OFF" OFF)
26
-
27
- set (CMAKE_CXX_STANDARD 20 )
26
+ set (CMAKE_CXX_STANDARD 17)
27
+ set (CXX_STANDARD_REQUIRED ON )
28
28
set (CMAKE_CXX_EXTENSIONS OFF )
29
29
SET (CMAKE_COMPILE_WARNING_AS_ERROR ON ) # turn off with --compile-no-warning-as-error
30
30
31
+
31
32
if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
32
33
# https://stackoverflow.com/questions/77153800/xcode-15-c-compilation-errors
33
34
# TODO ...
Original file line number Diff line number Diff line change @@ -50,7 +50,11 @@ namespace a4z {
50
50
" Wanted sized T cannot be greater than actual size N" );
51
51
astr<T + 1 > result;
52
52
constexpr std::size_t start = N - T - 1 ; // N > T is asserted above
53
- std::copy (data + start, data + N, result.data );
53
+ // cpp20, not yet
54
+ // std::copy(data + start, data + N, result.data);
55
+ for (size_t i = start; i < N; ++i) {
56
+ result.data [i - start] = data[i];
57
+ }
54
58
return result;
55
59
}
56
60
@@ -60,7 +64,11 @@ namespace a4z {
60
64
" Wanted sized T cannot be greater than actual size N" );
61
65
astr<T + 1 > result;
62
66
constexpr std::size_t last = T;
63
- std::copy (data, data + last, result.data );
67
+ // cpp20, not yet
68
+ // std::copy(data, data + last, result.data);
69
+ for (size_t i = 0 ; i < last; ++i) {
70
+ result.data [i] = data[i];
71
+ }
64
72
return result;
65
73
}
66
74
};
@@ -149,7 +157,7 @@ namespace a4z {
149
157
return npos; // Not found
150
158
}
151
159
152
- consteval bool on_windows () {
160
+ constexpr bool on_windows () {
153
161
#ifdef _WIN32
154
162
return true ;
155
163
#else
Original file line number Diff line number Diff line change @@ -14,13 +14,13 @@ namespace a4z {
14
14
constexpr char slash = on_windows() ? ' \\ ' : ' /' ;
15
15
16
16
#define a4z_file_name \
17
- []() consteval { \
17
+ []() constexpr { \
18
18
constexpr const char * str = __FILE__; \
19
19
constexpr auto len = a4z::cstr_len (str); \
20
20
constexpr auto start{a4z::find_nth_r_occurrence (__FILE__, a4z::slash, 2 )}; \
21
21
static_assert (start != a4z::npos); \
22
22
constexpr std::size_t astr_len = len - start; \
23
- char data[astr_len]; \
23
+ char data[astr_len] = { 0 }; \
24
24
for (std::size_t i = 0 ; i < astr_len; ++i) { \
25
25
data[i] = *(str + start + i + 1 ); \
26
26
} \
Original file line number Diff line number Diff line change @@ -82,14 +82,22 @@ SCENARIO("Test with filename macro") {
82
82
constexpr auto fn = a4z_file_name ();
83
83
84
84
WHEN (" checking if it starts with base" ) {
85
- const auto starts_with_base = std::string (fn.c_str ()).starts_with (" base" );
85
+ // cpp20
86
+ // const auto starts_with_base =
87
+ // std::string(fn.c_str()).starts_with("base");
88
+ const char * base = " base" ;
89
+ auto start_str = fn.first_n <4 >();
90
+ const auto starts_with_base = a4z::equal (base, start_str.c_str ());
86
91
THEN (" we find it at the expected position" ) {
87
92
CHECK (starts_with_base);
88
93
}
89
94
}
90
95
AND_WHEN (" checking if it ends with " ) {
91
- const auto ends_with_filename =
92
- std::string (fn.c_str ()).ends_with (" filename_test.cpp" );
96
+ const char * filename = " filename_test.cpp" ;
97
+ auto end_str = fn.last_n <17 >();
98
+ const auto ends_with_filename = a4z::equal (filename, end_str.c_str ());
99
+ // cpp20
100
+ // std::string(fn.c_str()).ends_with("filename_test.cpp");
93
101
THEN (" we find it at the expected position" ) {
94
102
CHECK (ends_with_filename);
95
103
}
You can’t perform that action at this time.
0 commit comments