Skip to content

Commit 7f7d708

Browse files
authored
book: remove default template parameters (#194)
1 parent 69aa4f0 commit 7f7d708

File tree

2 files changed

+0
-51
lines changed

2 files changed

+0
-51
lines changed

book/en-us/02-usability.md

-22
Original file line numberDiff line numberDiff line change
@@ -709,28 +709,6 @@ int main() {
709709
}
710710
```
711711
712-
### Default template parameters
713-
714-
We may have defined an addition function:
715-
716-
```cpp
717-
template<typename T, typename U>
718-
auto add(T x, U y) -> decltype(x+y) {
719-
return x+y;
720-
}
721-
```
722-
723-
However, when used, it is found that to use add, you must specify the type of its template parameters each time.
724-
725-
A convenience is provided in C++11 to specify the default parameters of the template:
726-
727-
```cpp
728-
template<typename T = int, typename U = int>
729-
auto add(T x, U y) -> decltype(x+y) {
730-
return x+y;
731-
}
732-
```
733-
734712
### Variadic templates
735713
736714
The template has always been one of C++'s unique **Black Magic**.

book/zh-cn/02-usability.md

-29
Original file line numberDiff line numberDiff line change
@@ -619,35 +619,6 @@ int main() {
619619
}
620620
```
621621
622-
### 默认模板参数
623-
624-
我们可能定义了一个加法函数:
625-
626-
```cpp
627-
// c++11 version
628-
template<typename T, typename U>
629-
auto add(T x, U y) -> decltype(x+y) {
630-
return x+y;
631-
}
632-
633-
// Call add function
634-
auto ret = add<int, int>(1,3);
635-
```
636-
637-
但在使用时发现,要使用 `add`,就必须每次都指定其模板参数的类型。
638-
639-
在 C++11 中提供了一种便利,可以指定模板的默认参数:
640-
641-
```cpp
642-
template<typename T = int, typename U = int>
643-
auto add(T x, U y) -> decltype(x+y) {
644-
return x+y;
645-
}
646-
647-
// Call add function
648-
auto ret = add(1,3);
649-
```
650-
651622
### 变长参数模板
652623
653624
模板一直是 C++ 所独有的**黑魔法**(一起念:**Dark Magic**)之一。

0 commit comments

Comments
 (0)