C++相談室 part50
■ このスレッドは過去ログ倉庫に格納されています
003229
2006/06/05(月) 13:52:17例えば配列の要素数を返す関数はこうなる。
template<typename T, std::size_t N> inline std::size_t numberof(T (&)[N]) {return N;}
でもまぁ、>31の言うように普通にvectorを渡せよって気もする。
static bool find(std::vector<int> const & foo, int ch)
{
std::vector<int>::const_iterator it = std::find(foo.begin(), foo.end(), ch);
return !(it == foo.end());
}
const int foo[] = {1, 3, 4, 6, 8, 10, 12};
std::vector<int> vfoo(foo, foo + sizeof(foo) / sizeof(* foo));
cout << func(vfoo, 2) ? "Found" : "Not found";
// ブラウザで直書きだから間違ってたらゴメン。
■ このスレッドは過去ログ倉庫に格納されています