[表示 : 全て 最新50 1-99 101- 201- 301- 401- 501- 601- 701- 801- 901- 1001- 2ch.scのread.cgiへ]
Update time : 03/03 12:56 / Filesize : 271 KB / Number-of Response : 1015
[このスレッドの書き込みを削除する]
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧] [類似スレッド一覧]


↑キャッシュ検索、類似スレ動作を修正しました、ご迷惑をお掛けしました

C++相談室 part130



215 名前:デフォルトの名無しさん (ワッチョイ 0b75-93S+) [2017/04/19(水) 16:39:33.18 ID:q88wQIwA0.net]
>>209
色々方法あるけど

*1 単純にオーバーロードを重ねる

template<typename T, typename Ti> double somefunc_impl(T* src0, T* src1, int t){}

double somefunc(float* src0, float* src1, int t){
return somefunc_impl<float,double>(src0,src1,t);
}

double somefunc(short* src0, short* src1, int t){
return somefunc_impl<short,int64 >(src0,src1,t);
}
double somefunc(double* src0, double* src1, int t){
return somefunc_impl<double,double>(src0,src1,t);
}

*2 trait (somefunc_internal_typeを定義していない型だけ渡すとコンパイルエラー)
template<typename T>struct somefunc_internal_type{};
template<>struct somefunc_internal_type<float>{ using type = double; };
template<>struct somefunc_internal_type<double>{ using type = double; };
template<>struct somefunc_internal_type<short>{ using type = int64_t; };

template<typename T, typename Ti = somefunc_internal_type<T>::type> double somefunc(T* src0, T* src1, int t){}


規則性があるならtraitsはenable_ifとかで少なく書けるが、深入りするとC++の闇にのまれるからおすすめしない
using type = double; を typedef double type; に変えたらたぶんVS2008でも使える






[ 続きを読む ] / [ 携帯版 ]

全部読む 前100 次100 最新50 [ このスレをブックマーク! 携帯に送る ] 2chのread.cgiへ
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧]( ´∀`)<271KB

read.cgi ver5.27 [feat.BBS2 +1.6] / e.0.2 (02/09/03) / eucaly.net products.
担当:undef