xref: /llvm-project/libcxx/test/std/utilities/memory/specialized.algorithms/buffer.h (revision 754ea6fd4d52f4699644a3c6dfc854a231c881c4)
1*754ea6fdSKonstantin Varlamov // -*- C++ -*-
2*754ea6fdSKonstantin Varlamov //===----------------------------------------------------------------------===//
3*754ea6fdSKonstantin Varlamov //
4*754ea6fdSKonstantin Varlamov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*754ea6fdSKonstantin Varlamov // See https://llvm.org/LICENSE.txt for license information.
6*754ea6fdSKonstantin Varlamov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*754ea6fdSKonstantin Varlamov //
8*754ea6fdSKonstantin Varlamov //===----------------------------------------------------------------------===//
9*754ea6fdSKonstantin Varlamov 
10*754ea6fdSKonstantin Varlamov #ifndef LIBCPP_TEST_STD_UTILITIES_MEMORY_SPECIALIZED_ALGORITHMS_BUFFER_H
11*754ea6fdSKonstantin Varlamov #define LIBCPP_TEST_STD_UTILITIES_MEMORY_SPECIALIZED_ALGORITHMS_BUFFER_H
12*754ea6fdSKonstantin Varlamov 
13*754ea6fdSKonstantin Varlamov template <typename T, int N>
14*754ea6fdSKonstantin Varlamov struct Buffer {
15*754ea6fdSKonstantin Varlamov   alignas(T) char buffer[sizeof(T) * N] = {};
16*754ea6fdSKonstantin Varlamov 
beginBuffer17*754ea6fdSKonstantin Varlamov   T* begin() { return reinterpret_cast<T*>(buffer); }
endBuffer18*754ea6fdSKonstantin Varlamov   T* end() { return begin() + N; }
cbeginBuffer19*754ea6fdSKonstantin Varlamov   const T* cbegin() const { return reinterpret_cast<const T*>(buffer); }
cendBuffer20*754ea6fdSKonstantin Varlamov   const T* cend() const { return cbegin() + N; }
21*754ea6fdSKonstantin Varlamov 
sizeBuffer22*754ea6fdSKonstantin Varlamov   constexpr int size() const { return N; }
23*754ea6fdSKonstantin Varlamov };
24*754ea6fdSKonstantin Varlamov 
25*754ea6fdSKonstantin Varlamov #endif // LIBCPP_TEST_STD_UTILITIES_MEMORY_SPECIALIZED_ALGORITHMS_BUFFER_H
26