forked from SilverMaple/STLSourceCodeNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_9_1_config6.cpp
More file actions
36 lines (30 loc) · 1.02 KB
/
1_9_1_config6.cpp
File metadata and controls
36 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// file: 1config6.cpp
// test __STL_FUNCTION_TMPL_PARTIAL_ORDER in <stl_config.h>
// vc6[x] cb4[o] gcc[o]
// 如果编译器支持partial ordering of function templates
// 或者说partial specialization of function templates就定义。
#include <iostream>
using namespace std;
class alloc {
};
template <class T, class Alloc=alloc>
class vec {
public:
void swap(vec<T, Alloc>&) {
cout << "swap()" << endl;
}
};
// inline内联函数,解决一些频繁调用的小函数大量消耗栈空间(栈内存)的问题
// inline只适合函数体内代码简单的函数使用,不能包含复杂的结构控制语句例如 while、switch,并且不能内联函数本身不能是直接递归函数
// 定义在类中的成员函数默认都是内联的,类外实现需加上inline
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class T, class Alloc>
inline void swap(vec<T, Alloc>& x, vec<T, Alloc>& y) {
x.swap(y);
cout << "inline swap" << endl;
}
#endif
int main() {
vec<int> x, y;
swap(x, y);
}