Public Member Functions | List of all members
makeTransformedSpanDocumentation1TestClass Struct Reference

Public Member Functions

float accumulate (std::vector< std::unique_ptr< float >> const &v)
 
void scale (std::vector< std::unique_ptr< float >> &v, float factor)
 
void analyse_accumulate ()
 
void analyse_scale ()
 
void analyse ()
 

Detailed Description

Definition at line 290 of file span_test.cc.

Member Function Documentation

float makeTransformedSpanDocumentation1TestClass::accumulate ( std::vector< std::unique_ptr< float >> const &  v)
inline

Definition at line 304 of file span_test.cc.

305  {
306  float sum = 0.0F;
307  for (float v: util::make_transformed_span(v, [](auto& ptr){ return *ptr; }))
308  sum += v;
309 
310  return sum;
311  } // accumulate()
auto make_transformed_span(BIter begin, EIter end, Op &&op)
Definition: span.h:294
void makeTransformedSpanDocumentation1TestClass::analyse ( )
inline

Definition at line 362 of file span_test.cc.

void makeTransformedSpanDocumentation1TestClass::analyse_accumulate ( )
inline

Definition at line 330 of file span_test.cc.

331  {
332  float const salt = 3.0;
333  constexpr std::size_t N = 10;
334 
335  std::vector<std::unique_ptr<float>> data;
336  for (auto i: util::counter(N))
337  data.push_back(std::make_unique<float>(salt * i));
338 
339  float sum = accumulate(data);
340  float const expectedSum = (N * (N - 1) / 2) * salt;
341 
342  BOOST_TEST(sum == expectedSum);
343 
344  } // analyse_accumulate()
float accumulate(std::vector< std::unique_ptr< float >> const &v)
Definition: span_test.cc:304
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
void makeTransformedSpanDocumentation1TestClass::analyse_scale ( )
inline

Definition at line 346 of file span_test.cc.

347  {
348  constexpr std::size_t N = 10;
349  const float factor = 3.0F;
350 
351  std::vector<std::unique_ptr<float>> data;
352  for (auto i: util::counter(N))
353  data.push_back(std::make_unique<float>(i));
354 
355  scale(data, factor);
356 
357  for (auto&& [ i, ptr ]: util::enumerate(data))
358  BOOST_TEST(*ptr == factor * i);
359 
360  } // analyse_scale()
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
void scale(std::vector< std::unique_ptr< float >> &v, float factor)
Definition: span_test.cc:322
void makeTransformedSpanDocumentation1TestClass::scale ( std::vector< std::unique_ptr< float >> &  v,
float  factor 
)
inline

Definition at line 322 of file span_test.cc.

323  {
324 
325  for (float& v: util::make_transformed_span(v, [](auto& ptr) -> float& { return *ptr; }))
326  v *= factor;
327 
328  } // scale()
auto make_transformed_span(BIter begin, EIter end, Op &&op)
Definition: span.h:294

The documentation for this struct was generated from the following file: