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 //===----------------------------------------------------------------------===//
9 #ifndef SUPPORT_TEST_CONSTEXPR_CONTAINER_H
10 #define SUPPORT_TEST_CONSTEXPR_CONTAINER_H
12 // A dummy container with enough constexpr support to test the standard
13 // insert iterators, such as `back_insert_iterator`.
20 #include "test_macros.h"
22 #if TEST_STD_VER >= 14
24 template<class T
, int N
>
25 class ConstexprFixedCapacityDeque
{
31 using const_iterator
= T
const *;
33 constexpr ConstexprFixedCapacityDeque() = default;
34 constexpr iterator
begin() { return data_
; }
35 constexpr iterator
end() { return data_
+ size_
; }
36 constexpr const_iterator
begin() const { return data_
; }
37 constexpr const_iterator
end() const { return data_
+ size_
; }
38 constexpr std::size_t size() const { return size_
; }
39 constexpr const T
& front() const { assert(size_
>= 1); return data_
[0]; }
40 constexpr const T
& back() const { assert(size_
>= 1); return data_
[size_
-1]; }
42 constexpr iterator
insert(const_iterator pos
, T t
) {
43 int i
= static_cast<int>(pos
- data_
);
45 std::move_backward(data_
+ i
, data_
+ size_
, data_
+ size_
+ 1);
47 data_
[i
] = std::move(t
);
52 constexpr void push_back(T t
) { insert(end(), std::move(t
)); }
53 constexpr void push_front(T t
) { insert(begin(), std::move(t
)); }
56 #endif // TEST_STD_VER >= 14
58 #endif // SUPPORT_TEST_CONSTEXPR_CONTAINER_H