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