add constexpr-array-shim to test constexpr on C++14

This commit is contained in:
Ferdinand Bachmann
2020-04-18 14:15:25 +02:00
parent 97c4bed1ec
commit fba15b1a72
4 changed files with 79 additions and 18 deletions
+11 -9
View File
@@ -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,9 +14,9 @@ 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);
const ring_buffer<int, 4>& const_buf = buf;
constexpr_array<int, 4> init{0, 0, 0, 0};
basic_ring_buffer<constexpr_array<int, 4>> buf(init);
const basic_ring_buffer<constexpr_array<int, 4>>& const_buf = buf;
buf.push_back(1);
buf.push_back(2);
@@ -24,8 +26,8 @@ constexpr bool test() {
buf.push_back(6);
{
std::array<int, 4> expected{3, 4, 5, 6};
std::array<int, 4> actual{0, 0, 0, 0};
constexpr_array<int, 4> expected{3, 4, 5, 6};
constexpr_array<int, 4> actual{0, 0, 0, 0};
int actual_index = 0;
for (const int& i : const_buf) {
actual[actual_index++] = i;
@@ -36,8 +38,8 @@ constexpr bool test() {
buf.push_back(7);
{
std::array<int, 4> expected{4, 5, 6, 7};
std::array<int, 4> actual{0, 0, 0, 0};
constexpr_array<int, 4> expected{4, 5, 6, 7};
constexpr_array<int, 4> actual{0, 0, 0, 0};
int actual_index = 0;
for (const int& i : const_buf) {
actual[actual_index++] = i;
@@ -48,7 +50,7 @@ constexpr bool test() {
return true;
}
static_assert(test());
static_assert(test(), "");
#endif
int main() {}