名前空間
変種
操作

Function template

提供: cppreference.com
< cpp‎ | language

 
 
C + +言語
一般的なトピック
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
フロー制御
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件付き実行文
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
繰り返し文
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
文をジャンプします
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
指定子
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
明示 (C++11)
静的
特殊なメンバ関数
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 

目次

[編集] 説明

テンプレートには、それを複数回書き換えを必要とせず、様々なタイプの仕事という汎用関数の設計を可能にします
Original:
Templates allow generic function design that work on various types, without the need of rewriting it multiple times
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 構文

[編集] 宣言

template < template_arguments > function_declaration (1)
export template < template_arguments > function_declaration (2) (C + + 11時まで)
テンプレート化された関数が呼び出されたときに関数本体が表示されている必要があり引用エラー: <ref> タグに対応する </ref> タグが不足しています
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#エクスポートされたテンプレート関数の宣言。関数本体は別のファイルに定義することができるで引用エラー: <ref> タグに対応する </ref> タグが不足しています
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 引数

class identifier (1)
typename identifier (2)
integral_type identifier (3)
class identifier = type_name (4) (C + + 11以来)
typename identifier = type_name (5) (C + + 11以来)
integral_type identifier = const_expr (6) (C + + 11以来)
1-2)
関数の内部でidentifierは、型として使用することができます
Original:
Inside the function identifier can be used as a type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
関数の内部でidentifierは定数として使用することができます
Original:
Inside the function identifier can be used as a constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4-6)
デフォルト引数
Original:
Default arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] スペシャ

template <> ret function_name < template_args > ( func_args ) body
専門化は、特定のテンプレートパラメータのテンプレート関数の実装を変更します
Original:
Specialization changes the implementation of the template function for specific template parameters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] コー​​ル

function_name < template_args > ( func_args ) (1)
function_name ( unambiguous_func_args ) (2)
func_argsは型と完全に一致しない場合#では、明示的なテンプレート引数は、テンプレート宣言(与えtemplate_args付き)のように通常の鋳造が行われます
Original:
# Explicit template arguments, if func_args don't match perfectly with the types as in the template declaration (with the given template_args) the usual casting will occur
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の引数から推論#暗黙のテンプレート引数、。曖昧さが存在することができません
Original:
# Implicit template arguments, deduced from the function arguments. No ambiguity can be present
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

[edit]
template<typename T>
struct S {
    template<typename U> void foo(){}
};
 
template<typename T>
void bar()
{
    S<T>s;
    s.foo<T>(); // error: < parsed as less than operator
    s.template foo<T>(); // OK
}


[編集] も参照してください

[編集] ノート

Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.