Android-cuttlefish cvd tool
static_vec.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright 2019, The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef TEEUI_STATIC_VEC_H_
19#define TEEUI_STATIC_VEC_H_
20
21#include <stddef.h> // for size_t
22
23#ifdef TEEUI_USE_STD_VECTOR
24#include <vector>
25#endif
26
27namespace teeui {
28
39#ifndef TEEUI_USE_STD_VECTOR
40template <typename T> class static_vec {
41 private:
43 size_t size_;
44
45 public:
46 static_vec() : data_(nullptr), size_(0) {}
48 template <size_t s> static_vec(T (&arr)[s]) : data_(&arr[0]), size_(s) {}
49 static_vec(const static_vec&) = default;
50 static_vec(static_vec&&) = default;
51 static_vec& operator=(const static_vec&) = default;
53
54 T* data() { return data_; }
55 const T* data() const { return data_; }
56 size_t size() const { return size_; }
57
58 T* begin() { return data_; }
59 T* end() { return data_ + size_; }
60 const T* begin() const { return data_; }
61 const T* end() const { return data_ + size_; }
62};
63#else
64template <typename T> using static_vec = std::vector<T>;
65#endif
66
67} // namespace teeui
68
69#endif // TEEUI_STATIC_VEC_H_
Definition: static_vec.h:40
static_vec & operator=(const static_vec &)=default
const T * begin() const
Definition: static_vec.h:60
T * begin()
Definition: static_vec.h:58
size_t size_
Definition: static_vec.h:43
static_vec(T(&arr)[s])
Definition: static_vec.h:48
T * data_
Definition: static_vec.h:42
static_vec()
Definition: static_vec.h:46
static_vec(static_vec &&)=default
static_vec & operator=(static_vec &&)=default
size_t size() const
Definition: static_vec.h:56
static_vec(T *begin, T *end)
Definition: static_vec.h:47
const T * data() const
Definition: static_vec.h:55
T * end()
Definition: static_vec.h:59
const T * end() const
Definition: static_vec.h:61
T * data()
Definition: static_vec.h:54
static_vec(const static_vec &)=default
Definition: layout.h:28