mirror of
https://github.com/changkun/modern-cpp-tutorial.git
synced 2025-12-17 12:44:40 +03:00
revision #2: 检阅部分模板相关内容
This commit is contained in:
23
code/2/2.12.external.template.cpp
Normal file
23
code/2/2.12.external.template.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// 2.12.external.template.cpp
|
||||
// chapter 2 language usability
|
||||
// modern cpp tutorial
|
||||
//
|
||||
// created by changkun at changkun.de
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
template class std::vector<bool>; // forcely instantiation
|
||||
extern template class std::vector<double>; // external template for avoiding instantiation in this file
|
||||
|
||||
template<bool T> class MagicType {
|
||||
bool magic = T;
|
||||
};
|
||||
|
||||
int main() {
|
||||
// the >> in template
|
||||
std::vector<std::vector<int>> matrix;
|
||||
std::vector<MagicType<(1>2)>> magic;
|
||||
}
|
||||
Reference in New Issue
Block a user