-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hcheng] #201604182213 use auto to implement max in better performanc…
…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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |