Function template
提供: cppreference.com
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
目次 |
[編集] 説明
テンプレートには、それを複数回書き換えを必要とせず、様々なタイプの仕事という汎用関数の設計を可能にします
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.
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.
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.
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およびそれ以降) | |||||||
関数の内部でidentifierは、型として使用することができます
3) 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.
You can help to correct and verify the translation. Click here for instructions.
関数の内部でidentifierは定数として使用することができます
4-6) 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.
You can help to correct and verify the translation. Click here for instructions.
デフォルト引数
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.
You can help to correct and verify the translation. Click here for instructions.
[編集] スペシャ
This section is incomplete Reason: partial specialization |
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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
This section is incomplete Reason: better explanation/example |
[編集] 例
This section is incomplete |
このコードを実行します
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.
You can help to correct and verify the translation. Click here for instructions.