1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 #ifndef SUPPORT_TEST_CONSTEXPR_CONTAINER_H
9 #define SUPPORT_TEST_CONSTEXPR_CONTAINER_H
11 // A dummy container with enough constexpr support to test the standard
12 // insert iterators, such as `back_insert_iterator`.
18 #include "test_macros.h"
20 #if TEST_STD_VER >= 14
22 template<class T
, int N
>
23 class ConstexprFixedCapacityDeque
{
29 using const_iterator
= T
const *;
31 constexpr ConstexprFixedCapacityDeque() = default;
32 constexpr iterator
begin() { return data_
; }
33 constexpr iterator
end() { return data_
+ size_
; }
34 constexpr const_iterator
begin() const { return data_
; }
35 constexpr const_iterator
end() const { return data_
+ size_
; }
36 constexpr size_t size() const { return size_
; }
37 constexpr const T
& front() const { assert(size_
>= 1); return data_
[0]; }
38 constexpr const T
& back() const { assert(size_
>= 1); return data_
[size_
-1]; }
40 constexpr iterator
insert(const_iterator pos
, T t
) {
41 int i
= static_cast<int>(pos
- data_
);
43 std::move_backward(data_
+ i
, data_
+ size_
, data_
+ size_
+ 1);
45 data_
[i
] = std::move(t
);
50 constexpr void push_back(T t
) { insert(end(), std::move(t
)); }
51 constexpr void push_front(T t
) { insert(begin(), std::move(t
)); }
54 #endif // TEST_STD_VER >= 14
56 #endif // SUPPORT_TEST_CONSTEXPR_CONTAINER_H