コンテンツにスキップ

検索結果

(前の20件 | ) (20 | 50 | 100 | 250 | 500 件) を表示
  • autoキーワードが導入される前は、decltypeは型推論の手段として重要な役割を果たしていました。autoが登場した後も、decltypeは特定のコンテキストで依然として有用です。 これらの利点により、decltypeはC++プログラミングにおいて重要なツールとなっています。 decltypeの基本的な構文は次のとおりです。…
    22キロバイト (3,145 語) - 2024年5月25日 (土) 11:05
  • の先頭要素を返します。decltype(auto) を使用することで、戻り値の型が自動的に int& として推論されます。 auto との違い decltype(auto) は auto よりも強力で柔軟です。auto は式の値の型に基づいて推論されますが、decltype(auto)…
    69キロバイト (8,412 語) - 2024年5月25日 (土) 11:30
  • 初期化式の一部が省略された場合、推論された型は auto を指定した変数と同じになります。 decltype は、式の型を取得するためのキーワードです。decltype を使用すると、変数の型をその式の型に合わせることができます。一方、decltype(auto) は、decltype を使用しているような振る舞いを auto 宣言と組み合わせて行います。…
    22キロバイト (3,082 語) - 2024年5月23日 (木) 11:13
  • Point p{1, 2}; decltype(auto)の導入: decltype(auto)は、変数の型をその初期化式の型と同じにする新しい導入です。 // C++14 int x = 42; decltype(auto) y = x; // yの型はint ラムダ式内のautoパラメータ:…
    33キロバイト (4,784 語) - 2024年5月25日 (土) 11:25
  • consteval constexpr constinit const_cast continue co_await co_return co_yield decltype default delete do double dynamic_cast else enum explicit export extern…
    18キロバイト (172 語) - 2024年5月20日 (月) 23:01
  • auto(t.rend())が有効な式であり、その型がsentinel_for<decltype(ranges::rbegin(E))>をモデル化する場合、ranges::rend(E)は式的にauto(t.rend())と等価です。 Tがクラスまたは列挙型であり、auto
    16キロバイト (2,758 語) - 2024年6月3日 (月) 07:09
  • さらに、可変引数ラムダは部分適用にも使えます。 auto bindLambda = [](auto&&func, auto&&... args) { return [&](auto&&... moreArgs) { return func(std::forward<decltype(args)>(args)...…
    13キロバイト (1,846 語) - 2024年5月25日 (土) 11:07
  • C++では型安全性が重要視されており、autoキーワードを使ってコンパイラに型を推論させることができます。また、decltypeを使って式の型を取得できます。 #include <iostream> auto main() -> int { auto x = 5; // int auto y = 5.5; //…
    9キロバイト (1,183 語) - 2024年5月23日 (木) 12:13
  • std::size_t size = std::tuple_size<decltype(arr)>::value; // 3 using ElementType = std::tuple_element<1, decltype(arr)>::type; // int…
    11キロバイト (1,375 語) - 2024年5月26日 (日) 00:46
  • ずにジェネリックプログラミングを行うことができます。これは、C++11以降で導入されたautoキーワードや、C++14以降で導入されたdecltypeキーワードなどを活用することで実現されます。 例えば、autoキーワードを使用することで、関数テンプレートを定義せずにジェネリックな関数を作成することができます。以下にその例を示します。…
    43キロバイト (5,743 語) - 2024年6月27日 (木) 04:01
  • C++11で導入された後置戻値型関数宣言構文 auto (*ポインタ変数名)(引数の型1, 引数の型2, ...) -> 戻値型 ; 型推論により自動的に型を確定する方法 auto ポインタ変数名 = & 関数名 ; & 関数名 は 関数名 とも書くことが出来ます。 decltypeによる方法 decltype ( 関数名 )…
    20キロバイト (2,588 語) - 2024年9月5日 (木) 01:41
  • C++では、autoキーワードを使用して型推論を行うことができます。autoを使用することで、コンパイラが変数の初期値から型を推論します。 auto auto x = 10; // xはint型に推論される auto y = 3.14; // yはdouble型に推論される また、decltype
    16キロバイト (2,560 語) - 2024年5月23日 (木) 11:17
  • <utility> struct MyType { int getValue() { return 42; } }; auto main() -> int { decltype(std::declval<MyType>().getValue()) value; // MyTypeのgetValue()の返り値の型を取得…
    16キロバイト (2,247 語) - 2024年5月17日 (金) 01:32
  • std::variant<int, std::string> v = "hello"; std::visit([](auto&& arg) { if constexpr (std::is_same_v<std::decay_t<decltype(arg)>, int>) { std::cout << "int: " << arg…
    47キロバイト (6,393 語) - 2024年5月15日 (水) 02:01
  • double, std::string>& value) { std::visit([](const auto& val) { using T = std::decay_t<decltype(val)>; if constexpr (std::is_same_v<T, int>) { std::cout…
    9キロバイト (1,259 語) - 2024年5月30日 (木) 04:33
  • std::cout << "tuple1 size: " << std::tuple_size<decltype(tuple1)>::value << std::endl; // タプルの連結 auto tuple2 = std::tuple_cat(std::tuple{1, 2.0}, std::tuple{'a'…
    47キロバイト (6,536 語) - 2024年5月28日 (火) 22:32
  • { // 後始末処理をスコープを抜ける際に実行する std::unique_ptr<decltype(cleanup), std::function<void()>> guard( &cleanup, [](auto *ptr) { (*ptr)(); // 後始末処理を呼び出す }); // リソースの処理…
    34キロバイト (4,791 語) - 2024年5月13日 (月) 02:57
  • 戻り値のid式がlvalueであることに依存している有効なC++ 2020コードが動作を変更するか、コンパイルに失敗する可能性があります。例えば: decltype(auto) f(int&& x) { return (x); } // returns int&&; previously returned int&…
    92キロバイト (11,997 語) - 2024年6月10日 (月) 02:12
  • // コンパイル時に `x` が `private` メンバーであることをチェック  static_assert(std::is_same_v<decltype(x), private>, "x is not a private member"); }; これらの新機能は、C++…
    19キロバイト (2,027 語) - 2024年5月25日 (土) 07:00
  • 1990年代後半から、主要な言語でも型推論の部分的な導入が始まりました。C++では1998年にautoキーワード、2011年にdecltypeキーワードが導入されました。Javaでは2004年のJava 5から型推論の一部がサポートされるようになりました。…
    55キロバイト (9,256 語) - 2024年5月23日 (木) 22:39
(前の20件 | ) (20 | 50 | 100 | 250 | 500 件) を表示