rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
arrays_util.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
5template <
6 typename ValueType,
7 size_t source_col_count,
8 size_t source_row_count,
9 size_t target_col_count,
10 size_t target_row_count
11> constexpr std::array<std::array<ValueType, target_col_count>, target_row_count> initTableFromAnotherTable(
12 const std::array<std::array<ValueType, source_col_count>, source_row_count>& source,
13 const ValueType defaultValue
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}
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)
Definition arrays_util.h:11
std::remove_extent_t< decltype(config->mafDecoding)> ValueType
Definition init_maf.cpp:30