青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 311, comments - 0, trackbacks - 0, articles - 0
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

(搬運工)std::min and std::max

Posted on 2012-01-06 16:40 點點滴滴 閱讀(1514) 評論(0)  編輯 收藏 引用 所屬分類: 02 編程語言
Today I typed the following:
int t = (std::max)(timeout, lagtime);

Why did I put parentheses around std::max? Because windows.h defines (among other things) a max and a min macro. If you include windows.h the above code will not compile. For example the following:
#include "windows.h"
#include <algorithm>

void foo() {
int i = 5;
int j = 7;
int x = std::max(i,j);
}

Will produce the following error with Visual Studio C++ 2005:
1>test.cpp(7) : error C2589: '(' : illegal token on right side of '::'
1>test.cpp(7) : error C2143: syntax error : missing ';' before '::'

There are a number of ways to work around windows.h defining these two macros.

  • Use alternative names defined in windows.h.
    int x = _cpp_max(i,j);
    int y = _cpp_min(i,j);
    This is not portable; only works on Windows.

  • Define NOMINMAX before including windows.h. This might break existing code that assumes NOMINMAX is not defined.

  • Don't use std::min and std::max. Instead use the tertiary operator like so:
    int x = i > j ? i : j; // max(i,j)
    int y = i < j ? i : j; // min(i,j)
    This is portable but not as readable and more error prone.

  • Use using statements to make the code portable:
    using std::min;
    using std::max;
    int x = max(i,j);
    int y = min(i,j);
    This works but requires two more lines of code. You could also just use 'using namespace std;' but that might pull in more than you want.

  • Use std::min<int> and std::max<int>
    int x = std::max<int>(i,j);
    int y = std::min<int>(i,j);
    This requires you to specify the type. However in some cases this actually helps. For example:
    int i = 5;
    unsigned int j = 7;
    int x = (std::max)(i,j);
    int y = (std::min)(i,j);
    Note the 'unsigned'. Generates the following errors:
    1>test.cpp(7) : error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : 
    expects 3 arguments - 2 provided
    1> c:\program files\microsoft visual studio 8\vc\include\xutility(3190) :
    see declaration of 'std::max'
    1>test.cpp(7) : error C2782: 'const _Ty &std::max(const _Ty &,const _Ty &)' :
    template parameter '_Ty' is ambiguous
    1> c:\program files\microsoft visual studio 8\vc\include\xutility(3182) :
    see declaration of 'std::max'
    1> could be 'unsigned int'
    1> or 'int'
    By explicitly specifying type via <int> you remove the ambiguity.

  • Use (std::min) and (std::max)
    int i = 5;
    int j = 7;
    int x = (std::max)(i,j);
    int y = (std::min)(i,j);
    This works (as does the std::max<int>) because the C++ preprocessor requires '(' as the next preprocessing token following the macro name to preform the macro expansion.
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品永久在线| 美女视频网站黄色亚洲| 国产精品成人午夜| 亚洲综合成人在线| 久久综合中文色婷婷| 最近中文字幕mv在线一区二区三区四区| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲欧洲午夜| 亚洲欧美日韩一区二区三区在线| 国产一区二区三区观看| 欧美**字幕| 亚洲欧美日韩人成在线播放| 欧美福利视频| 午夜久久资源| 亚洲精华国产欧美| 国产欧美精品日韩| 欧美国产日本在线| 午夜精品偷拍| 亚洲精品乱码久久久久久| 香蕉久久a毛片| 亚洲精品中文字幕有码专区| 国产免费亚洲高清| 欧美激情一区二区三区不卡| 欧美专区18| 在线视频日韩| 亚洲国产影院| 久久亚洲私人国产精品va媚药| 一本大道久久a久久综合婷婷| 国产午夜精品久久| 欧美日韩一区精品| 免费看av成人| 久久久久久久久久久久久9999| 一本久久知道综合久久| 欧美国产精品一区| 久久婷婷国产综合国色天香 | 韩日精品在线| 国产精品久久久久久久久动漫| 免费日韩一区二区| 久久精品国产99| 亚洲在线电影| 亚洲精品一区二区三区在线观看| 久久一区精品| 久久久久久一区二区| 亚洲一区综合| 亚洲精品影院在线观看| 狠狠干综合网| 国产亚洲欧美激情| 国产精品久久久久久久免费软件| 欧美经典一区二区| 欧美成人综合一区| 免费观看久久久4p| 玖玖玖免费嫩草在线影院一区| 欧美一区2区视频在线观看| 亚洲一区制服诱惑| 亚洲一区精彩视频| 亚洲一二三区视频在线观看| 国产一区欧美日韩| 国产午夜精品理论片a级探花 | 欧美一区二区日韩一区二区| 一区二区激情小说| 一本色道久久88综合日韩精品| 亚洲国产高清aⅴ视频| 亚洲大胆在线| 91久久嫩草影院一区二区| 亚洲激情不卡| 日韩亚洲在线| 亚洲视频1区| 亚洲女人av| 欧美一区二区免费观在线| 久久av一区| 美乳少妇欧美精品| 国产伦精品一区| 国产区日韩欧美| 国产真实乱偷精品视频免| 黄色成人在线网站| 亚洲激情成人网| 亚洲精品中文字| 妖精成人www高清在线观看| 一区二区高清在线| 午夜日韩福利| 久久久久网址| 欧美激情一区二区三区不卡| 亚洲欧洲日本在线| 亚洲一区二区在线视频| 欧美影院在线播放| 久久综合给合久久狠狠狠97色69| 欧美成人首页| 欧美另类专区| 国产精品自拍一区| 亚洲成色最大综合在线| 99re66热这里只有精品4| 亚洲免费综合| 久久久中精品2020中文| 欧美好吊妞视频| 一本色道久久综合亚洲精品不| 亚洲欧美日韩网| 免费久久精品视频| 国产精品久久久91| 亚洲高清自拍| 亚洲欧美激情四射在线日| 久久天堂成人| 日韩午夜电影在线观看| 久久国产欧美| 欧美精品999| 国产视频一区二区在线观看| 国产在线观看91精品一区| 国语自产在线不卡| 国产精品国产三级国产aⅴ入口| 中文在线不卡| 欧美一区二区视频在线观看2020| 欧美亚州韩日在线看免费版国语版| 久久成人免费网| 国产一区视频在线观看免费| 欧美片网站免费| 欧美激情精品久久久久| 欧美sm视频| 欧美成人有码| 久久国产精品一区二区三区四区| 鲁大师影院一区二区三区| 亚洲日本欧美天堂| 欧美一级在线视频| 亚洲免费观看高清完整版在线观看熊 | 久久久久国产一区二区三区| 中日韩美女免费视频网址在线观看 | 欧美吻胸吃奶大尺度电影| 久久精品视频在线| 欧美电影免费观看网站| 欧美精品免费在线| 国产日韩精品一区二区三区| 极品av少妇一区二区| 日韩一区二区免费看| 久久久久久久久蜜桃| 亚洲日本中文字幕区| 欧美一进一出视频| 欧美日韩视频免费播放| 亚洲第一精品夜夜躁人人躁 | 这里只有精品电影| 久久精品亚洲乱码伦伦中文| 欧美另类69精品久久久久9999| 欧美在线视频导航| 亚洲尤物精选| 久久久999| 欧美高清视频一区二区三区在线观看 | 欧美午夜电影完整版| 在线观看国产精品网站| 亚洲国产精品免费| 999亚洲国产精| 一区二区高清视频| 在线视频欧美日韩| 中文久久精品| 中文久久精品| 日韩系列欧美系列| 亚洲欧美日韩成人| 亚洲自拍偷拍一区| 亚洲无玛一区| 麻豆91精品| 中文欧美日韩| 欧美电影在线观看完整版| 国产日韩在线一区二区三区| 亚洲美女区一区| 久久一区二区三区国产精品 | 欧美一二三视频| 亚洲激情视频在线观看| 欧美一区二区三区免费大片| 欧美成人小视频| 在线观看亚洲精品| 久久久久五月天| 欧美一区二区三区视频在线 | 中文一区二区在线观看| 欧美日本韩国一区二区三区| 亚洲人成网站精品片在线观看| 久久久久久9999| 久久全国免费视频| 在线成人www免费观看视频| 久久久99免费视频| 久久精品综合网| 亚洲国产精品尤物yw在线观看| 久久综合婷婷| 久久蜜桃精品| 国产一区二区三区奇米久涩| 亚洲欧美日韩国产中文| 欧美成人综合网站| 亚洲性xxxx| 久久久久久精| 国产三级精品三级| 午夜激情一区| 欧美在线观看天堂一区二区三区| 欧美顶级艳妇交换群宴| 亚洲乱亚洲高清| 亚洲手机成人高清视频| 国产日韩欧美三区| 麻豆av福利av久久av| 欧美日韩在线亚洲一区蜜芽| 欧美亚洲日本网站| 一本久久综合| 欧美日韩在线大尺度| 在线观看亚洲视频| 欧美一区二区三区精品电影| 久久精品国产亚洲aⅴ| 亚洲激情第一页|