2014年1月13日のブックマーク (2件)

  • C++11: Syntax and Feature

    C++11の文法と機能(C++11: Syntax and Feature) Copyright (C) 2013 江添亮. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GN

  • 最新のconstexpr

    constexprは何度も解説しているが、だいぶ昔のドラフトを元にしていたので、正式な規格とはずれている。今書いている参考書はもうしばらく時間がかかるので、とりあえずその間をつなぐために、constexprについて解説する。 constexpr変数 constexpr指定子をつけてリテラル型の変数を宣言すると、その変数はコンパイル時定数になる。変数の初期化式はコンパイル時定数でなければならない。 void f() { constexpr int x = 10 ; // OK、コンパイル時定数 int r = 0 ; constexpr int error = r ; // エラー } constexpr指定子をつけて関数を宣言すると、constexpr関数になる。constexpr関数は、コンパイル時に評価される。ただし、constexpr関数にはとても厳しい制限がある。 まず、仮引数の型