forked from Ferdi265/cxx-ring-buffer
add constexpr-array-shim to test constexpr on C++14
This commit is contained in:
@ -2,8 +2,10 @@
|
||||
#include <ring-buffer.h>
|
||||
|
||||
#ifdef RING_BUFFER_CONSTEXPR
|
||||
#include "constexpr-array-shim.h"
|
||||
|
||||
template <typename T, size_t N>
|
||||
constexpr bool array_equal(const std::array<T, N>& a, const std::array<T, N>& b) {
|
||||
constexpr bool array_equal(const constexpr_array<T, N>& a, const constexpr_array<T, N>& b) {
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
if (a[i] != b[i]) return false;
|
||||
}
|
||||
@ -12,8 +14,8 @@ constexpr bool array_equal(const std::array<T, N>& a, const std::array<T, N>& b)
|
||||
}
|
||||
|
||||
constexpr bool test() {
|
||||
std::array<int, 4> init{0, 0, 0, 0};
|
||||
ring_buffer<int, 4> buf(init);
|
||||
constexpr_array<int, 4> init{0, 0, 0, 0};
|
||||
basic_ring_buffer<constexpr_array<int, 4>> buf(init);
|
||||
|
||||
buf.push_back(1);
|
||||
buf.push_back(2);
|
||||
@ -23,8 +25,8 @@ constexpr bool test() {
|
||||
buf.push_back(6);
|
||||
|
||||
{
|
||||
std::array<int, 4> expected{13, 14, 15, 16};
|
||||
std::array<int, 4> actual{0, 0, 0, 0};
|
||||
constexpr_array<int, 4> expected{13, 14, 15, 16};
|
||||
constexpr_array<int, 4> actual{0, 0, 0, 0};
|
||||
int actual_index = 0;
|
||||
for (int& i : buf) {
|
||||
i += 10;
|
||||
@ -36,8 +38,8 @@ constexpr bool test() {
|
||||
buf.push_back(7);
|
||||
|
||||
{
|
||||
std::array<int, 4> expected{24, 25, 26, 17};
|
||||
std::array<int, 4> actual{0, 0, 0, 0};
|
||||
constexpr_array<int, 4> expected{24, 25, 26, 17};
|
||||
constexpr_array<int, 4> actual{0, 0, 0, 0};
|
||||
int actual_index = 0;
|
||||
for (int& i : buf) {
|
||||
i += 10;
|
||||
@ -49,7 +51,7 @@ constexpr bool test() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(test());
|
||||
static_assert(test(), "");
|
||||
#endif
|
||||
|
||||
int main() {}
|
||||
|
Reference in New Issue
Block a user