摘要: 语法如下: //直接调用 []{ cout<<"hello lambda1"<<endl; }(); //传递给对象 auto l=[]{ cout<<"hello lambda2"<<endl; }; l(); Lambda可以有参数 auto l2 = [](const string& s){ 阅读全文
posted @ 2020-05-08 23:36 啸傲风月 阅读(525) 评论(0) 推荐(0) 编辑
摘要: 自C++11起,template可拥有那种“可以接收个数不定之template实参”的参数。此能力称variaddic template。 #include <iostream>#include <bitset> void print(){ } template<typename T,typenam 阅读全文
posted @ 2020-05-08 22:29 啸傲风月 阅读(298) 评论(0) 推荐(0) 编辑
摘要: 语法如下: for(decl:coll){ statement } 举例: template <typename T> void printElements(const T& coll){ for(const auto& elem:coll){ cout<<elem<<endl; } } int a 阅读全文
posted @ 2020-05-08 22:19 啸傲风月 阅读(3025) 评论(0) 推荐(0) 编辑
摘要: 自C++11起,constexpr可用来让表达式核定于编译期,例如 constexpr int square(int x){ return x*x; } float a[square(9)];cout<<"size="<<sizeof(a)/sizeof(a[0])<<endl; 阅读全文
posted @ 2020-05-08 22:10 啸傲风月 阅读(148) 评论(0) 推荐(0) 编辑