Template:example editlink
|
|
This high-risk template has been protected from editing to prevent vandalism. Please discuss any changes on the talk page. |
These are templates used for syntax highlighting.
{{c|code |lang=language (optional)}}
- A base template that is intended to highlight code inline.
langis optional; value returned by {{get lang}} is used by default. Applies a semi-transparent dark background. - Example:
{{c|std::string(80, '_');}}results instd::string(80, '_'); - Example:
{{c|1= auto x = std::array{1, 2, 3};}}results inauto x = std::array{1, 2, 3}; - Note that
1=is necessary if an equal sign=is present somewhere in the expression.
- For code snippets in ranges (such as
[begin,end)), the {{range}} template family is preferred.
{{c multi|line1 |line2 (optional)|... |line8 (optional)|lang=language (optional)}}
- Alike {{c}}, supports multi-line code snippets (up to 8 lines).
langis optional; value returned by {{get lang}} is used by default. Code highlighting does not span across lines: avoid splitting string literals ("") and multi-line comments (/* */). - Example (note the padding spaces):
{{c multi|std::max(std::numeric_limits<int>::max(),| std::numeric_limits<int>::min())}} - or (note the convenient indentation):
{{c multi
|std::max(std::numeric_limits<int>::max(),
| std::numeric_limits<int>::min())}}- results in
std::max(std::numeric_limits<int>::max(),std::numeric_limits<int>::min()).
- Note that if an equal sign
=is present somewhere in the corresponding line, the leading|1=/|2=/|3=/.../|8=are necessary, e.g.{{c multi
|1=std::any = 42;
|2=std::any = 3.14;}} - results in
std::any = 42;std::any = 3.14;.
{{cc multi|line1 |line2 (optional)|... |line8 (optional)|lang=language (optional)}}
- Same as {{c multi}} just no background (e.g. the bounding box) is applied.
- Example (note the padding spaces):
{{cc multi|std::max(std::numeric_limits<int>::max(),| std::numeric_limits<int>::min())}}- or
{{cc multi|std::max(std::numeric_limits<int>::max(),|{{nbsp|9}}std::numeric_limits<int>::min())}}- or (note the convenient indentation):
{{cc multi
|std::max(std::numeric_limits<int>::max(),
| std::numeric_limits<int>::min())}}- results in
std::max(std::numeric_limits<int>::max(),std::numeric_limits<int>::min()).
{{c/core|code |lang=language (optional)}}
- Same as {{c}} just no background (e.g. the bounding box) is applied. Intended to be used in other templates only.
- Example:
{{c/core|std::puts("C++");}}results instd::puts("C++");
{{co|code |lang=language (optional)}}
- Same as {{c/core}} just no background (e.g. the bounding box) is applied. Intended to be used in tables where bounding boxes are set by the table's frame.
- Example:
{{co|std::basic_regex<char>}}results instd::basic_regex<char>
{{box|tags }}
- Alike {{c}}, applies one shared bounding box to a formatted text generated by several given tags.
- Example:
{{box|{{lc|std::pair}}{{tt|''<int, char>''()}}}}results in std::pair<int, char>() - Example:
{{ltt std|cpp/algorithm/swap}}{{tt|''<int>''}}{{c/core|(x, y);}}}}results in std::swap<int>(x, y);
{{box/core|tags }}
- Same as {{box}} just no background (e.g. the bounding box) is applied.
- Example:
{{box/core|{{c/core|std::common_reference_t<ranges::range_reference_t<R1>,}}<br>{{nbspt|24}}{{c/core|ranges::range_reference_t<R2>>}}}}- results in
std::common_reference_t<ranges::range_reference_t<R1>,ranges::range_reference_t<R2>>
{{cc|code |lang=language (optional)}}
- A base template that is intended to highlight larger amounts of code inline. Usually used when the {{c}} template doesn't display the code readable, but {{source}} would waste too much space.
langis optional; value returned by {{get lang}} is used by default. - Example:
{{cc|1= assert(std::hypot(3, 4) == 5);}}results inassert(std::hypot(3, 4) == 5);
{{source|code |lang=language (optional)}}
- A base template that is intended to highlight large amounts of code.
langis optional; value returned by {{get lang}} is used by default. - For example, the code:
{{source|1=
int main()
{
__builtin_printf("Hello, C++\n");
}
}}
- results in
int main()
{
__builtin_printf("Hello, C++\n");
}
{{eq fun|code1 |code2 (optional)|... |code4 (optional)|lang=language (optional)}}
- A base template for representing code snippets in Possible implementation sections. The arguments
code1,code2, etc. are code for each version of the function template being described (e.g., std::fill-family in the case below). If no code is supplied at all, the template results in {{todo}}.langis optional — value returned by {{get lang}} is used by default. - For example, the code:
{{eq fun
| 1=
template<class ForwardIt, class T>
void fill(ForwardIt first, ForwardIt last, const T& value)
{
for (; first != last; ++first)
*first = value;
}
| 2=
template<class OutputIt, class Size, class T>
OutputIt fill_n(OutputIt first, Size count, const T& value)
{
for (Size i = 0; i < count; i++)
*first++ = value;
return first;
}
}}
- results in:
| First version |
|---|
template<class ForwardIt, class T>
void fill(ForwardIt first, ForwardIt last, const T& value)
{
for (; first != last; ++first)
*first = value;
}
|
| Second version |
template<class OutputIt, class Size, class T>
OutputIt fill_n(OutputIt first, Size count, const T& value)
{
for (Size i = 0; i < count; i++)
*first++ = value;
return first;
}
|
{{eq impl|code1 |code2 (optional)|... |code4 (optional)|title1 (optional)|... |title4 (optional)|lang=language (optional)}}
Additional params:
{{eq impl|ver1=link1 |... |ver4=link4 (optional)}}
- Same as {{eq fun}} with two additional capabilities:
- A substitution of any of the default title with a custom one via optional parameter(s)
title1=Your title, ...,title4=Your title . Default titles are the same as of aforementioned template {{eq fun}}, i.e. First version, ..., Fourth version. - An auto-generation of internal link "under" the title text. If
verNis specified, this template generates an internal HTML link with target name "Version num". For example, ifver2=3the internal link "#Version 3" will be generated. This capability works together with generation of internal anchors by {{dcla}} and {{dcl rev multi}} to link Possible implementation code sections to declarations in Synopsis.
{{example|description (optional)|lang=language (optional)|std=language standard (optional)|code=code to display |p=true if nondeterministic (optional)|output=sample output (optional)}}
- A base template to represent examples. If
codeis not present, the template results in {{todo}}.langdefaults to a value returned by {{get lang}}.outputspecifies the output which is displayed by the code. If the output is not deterministic,pshould be set totrueto indicate this (then "Possible output:" is shown instead of just "Output:").
- The following language standards are available:
- cxx98, cxx03, cxx11, cxx14, c89, c99, c11.
- For example, the code:
{{example
| Commenting string
| code=
int main()
{
__builtin_puts("Hello, C++");
}
| p=true
| output=
Hello, C++
}}
- results in:
Commenting string
int main()
{
__builtin_puts("Hello, C++");
}
Possible output:
Hello, C++
| The above documentation is transcluded from Template:source/doc. (edit | history) Subpages of this template. |