INT_[MIN|MAX] limit macros vs numeric_limits

后端 未结 5 649
故里飘歌
故里飘歌 2020-12-16 15:41

Is there any argument for using the numeric limits macros (e.g. INT64_MAX) over std::numeric_limits? From what I understand numeric_limits is in the standard but the macros

5条回答
  •  别那么骄傲
    2020-12-16 15:59

    Pre C++0x, definitely. INT_MIN and INT_MAX are integral constant expressions; numeric_limits::min() and numeric_limits::max() aren't. is standard C++, and unless you're dealing with templates (where you don't know whether it's int or long), there's really no reason to bother with the overly complicated solution. (Also: if you're writing templates, don't forget that numeric_limits::min() and numeric_limits::min() represent completely different attributes; if you want the minimum possible value, you'll need numeric_limits::is_integer ? numeric_limits::min() : -numeric_limits::max().)

提交回复
热议问题