c++ - Wrap raw data in std container like array, with runtime size -
c++ - Wrap raw data in std container like array, with runtime size -
is there std container fixed size std::array, size not compile time, runtime?
i want pass part of info have stored in std::array
std::acculumate
, similar functions. not want utilize std::vector (working on embedded platform), hence looking in between.
assume code this, want used in place of array_part
:
#include <array> #include <algorithm> #include <iostream> #include <numeric> #include <vector> int main() { std::array<float,100> somedata; // fill info int datacount = 50; std::array_part<float> partofdata(somedata.data(),datacount)); // <<<<< here const auto s_x = std::accumulate(partofdata.begin(), partofdata.end(), 0.0); }
if there no such container, how can wrap raw info have , nowadays them std::accumulate
, other std algorithms?
std::accumulate
takes iterators. can pass iterators contain range of interest:
auto start = partofdata.begin() + 42; auto end = partofdata.begin() + 77; const auto s_x = std::accumulate(start, end, 0.0);
alternatively, can roll out own non-owning container-like object. see this question example.
c++ arrays c++11 containers std
Comments
Post a Comment