今日のC++
覚えたこと。
- using namespace std;
- algorithmのなかにminとmaxはあるが、引数は2個限定。min_elementとかでリストの中の最小値の場所を得ることができるのでPythonのmin(xs)に相当するのはxs[min_element(xs.begin(), xs.end())]かな。
- <?=
- 最小値演算子 http://www.asahi-net.or.jp/~WG5K-ICKW/html/online/gcc-2.95.2/gcc_5.html thanks @renha
- 最新のgccからは取り除かれているのでTopCoder以外では使わない方がよさそう
- for(int i=0;i<xs.size();i++){result<?=f(xs[i])}とかやってPythonでいうところのmin(f(x) for x in xs)を実現する。
- 参照は右から読む
- templateの定義の最後にはセミコロンがいる
- template<0> struct Numbersって書いて怒られた。
- template<> struct Numbers<0>が正解。変なの。
- 最初のが自由度で、後のがどこに何がはまっているか
- template<int N><int M>
- expected unqualified-id before '<' token
- <int N, int M>だな
- wrong number of template arguments (1, should be 2)
-