Skip to content

curoles/cgem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CGem library

Online documentation

Allocate variable length array on stack

Macro [stack_array](@ref stack_array) hides an instance of Variable-length Automatic Array and instead exposes managing object of type [raw_ptr_array](@ref cgm::raw_ptr_array). If compiler does not support VLAA, then dynamic memory allocation is used.

TEST (StackArray, Iterators) {
    int sz{10};
    stack_array(int, sz, a);
    a[0] = 0; a[1] = 1; a[2] = a[1];
    std::fill(a.begin(), a.end(), 3);
    std::iota(a.begin(), a.end(), -4);
    int sum{0};
    for (auto elem : a) {
        sum += elem;
    }
    ASSERT_EQ(sum, std::accumulate(a.begin(), a.end(), 0));
}

Numeric range for C++11 range-based for loop

  for (auto i : num::range(5)) { // [0,5) = 0, 1, 2, 3, 4; the same as range(0, 5)

  for (auto i : num::range(5, 16, 3)) { // 5, 8, 11, 14; with step

  for (auto f : num::range(5.1, 8.3, 0.6)) { // with floating-point numbers

  for (auto i : num::range(16, 5, -3)) { // 16, 13, 10, 7; reversed

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published