Skip to content

Commit

Permalink
[hcheng] #201604182213 use auto to implement max in better performanc…
Browse files Browse the repository at this point in the history
…e for macro
  • Loading branch information
githubch committed Apr 18, 2016
1 parent 62a53df commit 59bd976
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions auto_sample/auto_applied_in_macro.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include<iostream>
#define Max(a,b) ((a > b) ? (a) : (b))
#define Max_(a,b) {\
auto _a = a;\
auto _b = b;\
return (_a > _b) ? _a:_b;}\
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Max_(a,b) ({ \
auto _a = (a); \
auto _b = (b); \
(_a > _b) ? _a:_b;})\


int main(int argc, char ** argv){
int a = 2;
int b = 3;
std::cout <<"Max(a, b)"<<Max(a,b)<<std::endl;
std::cout <<"Max(a, b)="<<Max(a,b)<<std::endl;
std::cout <<"3 * Max(a, b) should equal 9, and the result is "<<3*Max(a, b)<<std::endl;
int m = 2;
int n = 3;
std::cout <<"Max_(m, n)"<<Max_(m++, n++)<<std::endl;
std::cout <<"Max_(m, n)="<<Max_(m++, n++)<<std::endl;
std::cout <<"m="<<m<<std::endl;
std::cout <<"n="<<n<<std::endl;
}

0 comments on commit 59bd976

Please sign in to comment.