I'm having a look at the piece of code below, from std::chrono
, and I don't understand the _Rep(min)()
syntax.
I know _Rep
is the return type, and min
has to be the method name, but then:
_Rep(min)()
and _Rep min()
?zero
?template <class _Rep>
struct duration_values { // gets arithmetic properties of a type
_NODISCARD static constexpr _Rep zero() noexcept {
// get zero value
return _Rep(0);
}
_NODISCARD static constexpr _Rep(min)() noexcept {
// get smallest value
return numeric_limits<_Rep>::lowest();
}
_NODISCARD static constexpr _Rep(max)() noexcept {
// get largest value
return (numeric_limits<_Rep>::max)();
}
};
I've seen the same construct in numeric_limits
:
_NODISCARD static constexpr _Ty(min)() noexcept {
return _Ty();
}
_NODISCARD static constexpr _Ty(max)() noexcept {
return _Ty();
}
More info, just in case it's needed:
chrono
file is under Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.29.30130\include.And a little online example I've been playing with: https://godbolt.org/z/E5nW7x8vW
Its to defeat macro expansion; the Windows headers used to define macros named min
and max
.