Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
class_data_vec.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 #include "stdafx.h"
11 #include <array>
12 
17 template <typename T, size_t N>
18 class Data_Vec
19 {
20 public:
21  // CONSTRUCTORS
22  Data_Vec() = default;
23  Data_Vec(size_t size) { data.fill(std::vector<T>(size)); }
24 
25  // VARIABLES
26  std::array<std::vector<T>, N> data;
27 
28  // ELEMENT ACCESS
29  std::vector<T>& operator[](size_t i){ return data[i]; }
30  const std::vector<T>& operator[](size_t i) const { return data[i]; }
31 
32  // CAPACITY
33  size_t dim() const noexcept{ return data.size(); }
34  size_t size() const noexcept{ return data[0].size(); }
35  void resize (size_t n){
36  for (auto &vec : data) vec.resize(n);
37  }
38  void resize (size_t n, T val){
39  for (auto &vec : data) vec.resize(n, val);
40  }
41  void reserve(size_t n){
42  for (auto &vec : data) vec.reserve(n);
43  }
44  void erase(size_t index){
45  for (auto &vec : data) vec.erase(vec.begin() + index);
46  }
47  // MODIFIERS
48  void fill(T val){
49  for (auto &vec : data) std::fill(vec.begin(), vec.end(), val);
50  }
51 };
std::array< std::vector< T >, N > data
Data_Vec(size_t size)
size_t size() const noexcept
void erase(size_t index)
void resize(size_t n)
const std::vector< T > & operator[](size_t i) const
void fill(T val)
system include files and for project-specific include files that are used frequently but are changed ...
declaration in params.hpp
Definition: core_power.h:19
std::vector< T > & operator[](size_t i)
void reserve(size_t n)
Data_Vec()=default
size_t dim() const noexcept
void resize(size_t n, T val)