说在前面,试图从头开始看明白C++标准库的构成。
1.true_type,false_type
template <class _Ty, _Ty _Val>
struct integral_constant {
static constexpr _Ty value = _Val;
using value_type = _Ty;
using type = integral_constant;
constexpr operator value_type() const noexcept {
return value;
}
[[nodiscard]] constexpr value_type operator()() const noexcept {
return value;
}
};
template <bool _Val>
using bool_constant = integral_constant<bool, _Val>;
using true_type = bool_constant<true>;
using false_type = bool_constant<false>;
(1) 记住有叫integral_constant和 bool_constant的东西。
(2)::value是bool值。
2. enable_if
template <bool _Test, class _Ty = void>
struct enable_if