タグ付けされた質問 「decltype」

2
decltype(auto)の用途は何ですか?
OverаэтотвопросестьответынаStack Overflowнарусском:Конструкцияdecltype(auto) c ++ 14では、decltype(auto)イディオムが導入されています。 通常、その使用は、auto宣言でdecltype指定された式のルールを使用できるようにすることです。 イディオムの "良い"使用法の例を検索すると、(Scott Meyersによる)次のようなもの、つまり関数の戻り値の型の推定についてしか考えることができません。 template<typename ContainerType, typename IndexType> // C++14 decltype(auto) grab(ContainerType&& container, IndexType&& index) { authenticateUser(); return std::forward<ContainerType>(container)[std::forward<IndexType>(index)]; } この新しい言語機能が役立つ他の例はありますか?

2
関数の見出しにある矢印演算子(->)
私は次のコードに出くわしました: template <typename T, typename T1> auto compose(T a, T1 b) -> decltype(a + b) { return a+b; } 理解できないことが1つあります。 ->関数の見出しで矢印演算子()が何を意味するかはどこで確認できますか?純粋に論理的には、->演算子が型を決定し、それautoが推定されると思いますが、これをまっすぐに取得したいと思います。情報が見つかりません。
128 c++  c++11  auto  decltype 

2
std :: result_ofとdecltypeの違い
std::result_ofC ++ 0xでの必要性を理解するのに問題があります。私が正しく理解した場合result_ofは、特定のタイプのパラメーターを持つ関数オブジェクトを呼び出す結果のタイプを取得するために使用されます。例えば: template <typename F, typename Arg> typename std::result_of<F(Arg)>::type invoke(F f, Arg a) { return f(a); } 次のコードとの違いは本当にわかりません。 template <typename F, typename Arg> auto invoke(F f, Arg a) -> decltype(f(a)) //uses the f parameter { return f(a); } または template <typename F, typename Arg> auto invoke(F f, Arg a) …
100 c++  c++11  decltype  result-of 

6
C ++で参照が「const」ではないのはなぜですか?
「const変数」は、一度割り当てられると、次のように変数を変更できないことを示しています。 int const i = 1; i = 2; 上記のプログラムはコンパイルに失敗します。gccはエラーでプロンプトを出します: assignment of read-only variable 'i' 問題ありません、私はそれを理解できますが、次の例は私の理解を超えています: #include<iostream> using namespace std; int main() { boolalpha(cout); int const i = 1; cout << is_const<decltype(i)>::value << endl; int const &ri = i; cout << is_const<decltype(ri)>::value << endl; return 0; } 出力します true false …

3
C ++ decltypeと括弧-なぜですか?
主題は以前に議論されました が、これは重複ではありません。 decltype(a)との違いについて質問された場合decltype((a))、通常の答えは- aは変数で(a)あり、は式です。私はこの答えに満足できないと思います。 まず、a表現もです。一次式のオプションには、特に- (式) id式 さらに重要なことに、decltypeの表現では、括弧が非常に明示的に考慮されます。 For an expression e, the type denoted by decltype(e) is defined as follows: (1.1) if e is an unparenthesized id-expression naming a structured binding, ... (1.2) otherwise, if e is an unparenthesized id-expression naming a non-type template-parameter, ... (1.3) otherwise, if e …
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.