Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_vector.hpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TEUCHOS_VECTOR_HPP
11#define TEUCHOS_VECTOR_HPP
12
13#include <vector>
14#include <Teuchos_Assert.hpp>
15
16namespace Teuchos {
17
18/* just some wrappers over std::vector to let us
19 do all indexing with int */
20
21template <typename T>
22inline int size(std::vector<T> const& v) {
23 return int(v.size());
24}
25
26template <typename T>
27inline typename std::vector<T>::reference at(std::vector<T>& v, int i) {
28 TEUCHOS_DEBUG_ASSERT(0 <= i);
29 TEUCHOS_DEBUG_ASSERT(i < int(v.size()));
30 return v[std::size_t(i)];
31}
32
33template <typename T>
34inline typename std::vector<T>::const_reference at(std::vector<T> const& v, int i) {
35 TEUCHOS_DEBUG_ASSERT(0 <= i);
36 TEUCHOS_DEBUG_ASSERT(i < int(v.size()));
37 return v[std::size_t(i)];
38}
39
40template <typename T>
41inline void resize(std::vector<T>& v, int n) {
42 TEUCHOS_DEBUG_ASSERT(0 <= n);
43 v.resize(std::size_t(n));
44}
45
46template <typename T>
47inline void reserve(std::vector<T>& v, int n) {
48 TEUCHOS_DEBUG_ASSERT(0 <= n);
49 v.reserve(std::size_t(n));
50}
51
52template <typename T>
53inline std::vector<T> make_vector(int n, T const& init_val = T()) {
54 return std::vector<T>(std::size_t(n), init_val);
55}
56
57template <typename T>
58void add_back(std::vector<T>& vector, T& value) {
59 using std::swap;
60 vector.push_back(T());
61 swap(vector.back(), value);
62}
63
64}
65
66#endif
67
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...