【C++】template 統合スレ -- Part5
■ このスレッドは過去ログ倉庫に格納されています
0332デフォルトの名無しさん
NGNGtemplate <typename T>
class c
{
template <typename U> struct s{ typedef U type; };
template <typename U> struct s<U[?]>{ typedef U type; };
public:
typedef typename s<T>::type type;
};
template <typename T>
inline int
numof( const T& t ){
return sizeof( t ) / sizeof( t[ 0 ] );
}
template <typename T>
typename c<T>::type min_array( const T& t ){
return *std::min_element( t, t + numof( t ) );
}
int main(){
int n[] = { 1, 2, 3, 4, 5 };
std::cout << min_array( n ) << std::endl;
return 0;
}
頑張ってここまで考えたんですが、?にmain::nの要素数をコンパイルタイムで入れられなくて行き詰まっています…
■ このスレッドは過去ログ倉庫に格納されています