Skip to content

Commit 34dbdac

Browse files
committed
Fix: Enable constexpr byte_span construction in C++26?
1 parent 717cf00 commit 34dbdac

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

include/byte_span/byte_span.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <array>
44
#include <concepts>
55
#include <cstddef>
6+
#include <cstdint>
67
#include <iterator>
78
#include <new>
89
#include <ranges>

test/source/byte_span_4_constexpr_test.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// NOLINTBEGIN(misc-const-correctness,clang-analyzer-deadcode.DeadStores,unused-includes)
1+
// NOLINTBEGIN(misc-const-correctness,clang-analyzer-deadcode.DeadStores)
22
#if defined(__cpp_constexpr) && __cpp_constexpr >= 202207L // C++26
33
#include <algorithm>
44
#include <array>
@@ -15,7 +15,6 @@
1515

1616
#include "byte_span/byte_span.hpp"
1717

18-
1918
using range3::as_bytes;
2019
using range3::as_span;
2120
using range3::as_sv;
@@ -32,32 +31,28 @@ using namespace std::string_view_literals;
3231
#pragma GCC diagnostic ignored "-Wunused-variable"
3332
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
3433

35-
36-
3734
TEST_CASE("byte_span compile-time construction", "[byte_span]") {
38-
SECTION("from iterator and sentinel") {
39-
constexpr std::array<char, 4> arr = {'a', 'b', 'c', 'd'};
40-
constexpr byte_span view(arr.begin(), arr.end());
41-
STATIC_REQUIRE(view.size() == 4);
42-
REQUIRE(view.size() == 4);
43-
}
44-
45-
SECTION("from iterator and count") {
46-
constexpr std::array<char, 4> arr = {'a', 'b', 'c', 'd'};
47-
constexpr byte_span view(arr.begin(), 4);
48-
STATIC_REQUIRE(view.size() == 4);
49-
REQUIRE(view.size() == 4);
50-
}
51-
52-
/*
53-
SECTION("from std::array") {}
54-
SECTION("from C array") {}
55-
SECTION("from std::span") {}
56-
*/
35+
SECTION("from iterator and sentinel") {
36+
constexpr std::array<char, 4> arr = {'a', 'b', 'c', 'd'};
37+
constexpr byte_span view(arr.begin(), arr.end());
38+
STATIC_REQUIRE(view.size() == 4);
39+
REQUIRE(view.size() == 4);
40+
}
41+
42+
SECTION("from iterator and count") {
43+
constexpr std::array<char, 4> arr = {'a', 'b', 'c', 'd'};
44+
constexpr byte_span view(arr.begin(), 4);
45+
STATIC_REQUIRE(view.size() == 4);
46+
REQUIRE(view.size() == 4);
47+
}
48+
49+
/*
50+
SECTION("from std::array") {}
51+
SECTION("from C array") {}
52+
SECTION("from std::span") {}
53+
*/
5754
}
5855

59-
60-
6156
#pragma GCC diagnostic pop
6257

6358
#endif

0 commit comments

Comments
 (0)