私はバイナリサイズを減らすために、テンプレートメソッド内のコードの一部をテンプレート以外のメソッドに移動しようとしています。非テンプレートメソッドの引数としてテンプレートパラメータを使用できますか?
template<TargetType K, typename V = plat_target_handle_t>
class Target
{
.............
..............
};
TargetTypeに下に示すように、「ターゲット」と呼ばれるテンプレートクラスは、列挙型のデータ型があります。
template<>
template< TargetType T>
std::vector<Target<T> >
Target<TARGET_TYPE_X>::getChildren(const TargetState i_state) const
{
std::vector<Target<T> > l_children;
for (int i=0; i < elements_in_some_list ; ++i)
{
/*If the current entry in some_list match my critera, add to the l_children */
}
}
TargetTypeは列挙型のデータ型で、TARGET_TYPE_Xは列挙型の値の1つです。
私はすべてのロジックをグローバルメソッドに移動して、getChildrenHelperと言うことができます。
getChildrenHelperは次のように宣言されています。
void getGhildrenHelper(const TargetType i_targetType,
const TargetState i_targetstate,
std::vector<Target<TARGET_TYPE_ALL>> & io_children);
そしてGetChildrenメソッドは、最終的に
template<>
template< TargetType T>
std::vector<Target<T> >
Target<TARGET_TYPE_X>::getChildren(const TargetState i_state) const
{
std::vector<Target<T> > l_children;
childHelper(T,i_state,l_children);
return l_children;
}
のようになります。私の推測では、私が働いているネイティブコンパイラがエラー経由しませんでしたけれども、これは、実行することはできませんです。
は、しかし同様の概念が完全に正常に動作している別の既存のコードがある
template< TargetType K >
inline ReturnCode putParam(const Target<K>& i_target,
const RingID i_ringID,
const RingMode i_ringMode)
{
ReturnCode l_rc = FAPI2_RC_SUCCESS;
// Find the string in the SEEPROM
l_rc = findInImageAndApply(i_target, i_ringID, i_ringMode);
return l_rc;
}
fapi2::ReturnCode findImageAndApply(
const fapi2::Target<fapi2::TARGET_TYPE_ALL>& i_target,
const RingID i_ringID,
const fapi2::RingMode i_ringMode)
{
................
................
}
リファクタリングするサンプルプログラムはコンパイルされません。 'TargetType'、' TARGET_TYPE_X'、 'TargetState'、' plat_target_handle_t'の定義がありません。 – user2079303
TargetTypeとTargetStateは列挙型ですが、私はそれらについて精巧ではありません。同様に、plat_target_handle_tは他のところで定義されています。 –