MSVC源码阅读笔记1 - xtr1common.h

本文介绍了C++标准库中的几个关键模板,如integral_constant用于创建常量类型,enable_if和conditional用于条件编译,is_same用于类型比较,remove_cv移除const和volatile修饰,以及disjunction和相关的类型判断。这些内容对于理解和编写C++代码至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说在前面,试图从头开始看明白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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值