A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../numeric/valarray/indirect_array.html below:

std::indirect_array - cppreference.com

template< class T > class indirect_array;

std::indirect_array is a helper template used by the valarray subscript operator with std::valarray<std::size_t> argument. It has reference semantics to a subset of the array whose indices specified by the std::valarray<std::size_t> object.

[edit] Member types Type Definition value_type T [edit] Member functions [edit] Example
#include <iostream>
#include <valarray>
 
int main()
{
    std::valarray<int> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
    std::valarray<std::size_t> idx{0, 2, 4, 6, 8};
 
    std::cout << "Original valarray: ";
    for (int n : data)
        std::cout << n << ' ';
    std::cout << '\n';
 
    data[idx] += data[idx]; // double the values at indices 'idx'
 
    // the type of data[idx] is std::indirect_array<int>
 
    std::cout << "After indirect modification: ";
    for (int n : data)
        std::cout << n << ' ';
    std::cout << '\n';
}

Output:

Original valarray: 0 1 2 3 4 5 6 7 8 9 
After indirect modification: 0 1 4 3 8 5 12 7 16 9

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4