rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
arrays_util.h File Reference

Functions

template<typename ValueType , size_t source_col_count, size_t source_row_count, size_t target_col_count, size_t target_row_count>
constexpr std::array< std::array< ValueType, target_col_count >, target_row_count > initTableFromAnotherTable (const std::array< std::array< ValueType, source_col_count >, source_row_count > &source, const ValueType defaultValue)
 

Function Documentation

◆ initTableFromAnotherTable()

template<typename ValueType , size_t source_col_count, size_t source_row_count, size_t target_col_count, size_t target_row_count>
constexpr std::array< std::array< ValueType, target_col_count >, target_row_count > initTableFromAnotherTable ( const std::array< std::array< ValueType, source_col_count >, source_row_count > &  source,
const ValueType  defaultValue 
)
constexpr

Definition at line 11 of file arrays_util.h.

14 {
15 std::array<std::array<ValueType, target_col_count>, target_row_count> result {};
16 const size_t colCountToCopy = std::min(source_col_count, target_col_count);
17 const size_t rowCountToCopy = std::min(source_row_count, target_row_count);
18 for (size_t row = 0; row < rowCountToCopy; ++row) {
19 for (size_t col = 0; col < colCountToCopy; ++col) {
20 result[row][col] = source[row][col];
21 }
22 for (size_t col = colCountToCopy; col < target_col_count; ++col) {
23 result[row][col] = defaultValue;
24 }
25 }
26 for (size_t row = rowCountToCopy; row < target_row_count; ++row) {
27 for (size_t col = 0; col < target_col_count; ++col) {
28 result[row][col] = defaultValue;
29 }
30 }
31 return result;
32}

Go to the source code of this file.