容器访问宏

来源:互联网 发布:php在线序列化 编辑:程序博客网 时间:2024/04/29 18:32
#define PRINT_ELEMENTS(a)\ {for_each(a.begin(),a.end(),[](auto val){cout<<val<<" ";}); cout<<endl;}#define INSERT_ELEMENTS(v,b,e) {for(auto i = b;i < e;i++){v.push_back(i);}}
宏定义里面有 for(){}、 do{...}while(0) 、 if(){}、存在变量声明 加花括号
顺便说一下,尽量不要用宏,为了效率可以把函数设成inline
template<typename V>inline void PRINT_ELEMENTS(const V& v){for_each(v.begin(), v.end(), [](auto val) {cout << val << " "; }); cout << endl;}template<typename V, typename B, typename E>inline void INSERT_ELEMENTS(V& v, B b, E e){for (auto i = b; i < e; i++) {v.push_back(i); }}


                                             
0 0
原创粉丝点击