関数から自動ストレージ配列を返すことはできないため、std::vector<sc_uint<8>>
代わりに を返すことをお勧めします。sc_uint<8>
基本的に、使いやすく移動しやすい動的配列に値をラップするだけです。
次に、基準に基づいpush_back
て戻りたい値を単純に指定します。vector
例えば:
std::vector<sc_uint<8>> arrayfill(struct){
std::vecotr<sc_uint<8>> array;
array.reserve(10); // Reserves space for 10 elements.
array.push_back(struct.a); // This will be the first element in array, at index 0.
array.push_back(struct.b); // This will be the second element at index 1.
...
if (struct.trigger == false){
array.push_back(0);
}
else
{
array.push_back(struct.j);
}
// At this point, array will have as many elements as push_back has been called.
return array;
}
を使用しstd::vector::insert
て値の範囲を追加します。
array.insert(array.end(), &values[3], &values[6]);
values
いくつかの配列はどこにありますか。上記は、インデックス 3 からインデックス 5 までの値 (排他的範囲、インデックス 6 の値は挿入されません)values
を の末尾に挿入しarray
ます。