首页 > 解决方案 > std::array 的实现

问题描述

我正在查看 MSVC 的 std::array 实现并看到了这个:

#if _HAS_CXX17
template <class _First, class... _Rest>
struct _Enforce_same {
    static_assert(conjunction_v<is_same<_First, _Rest>...>,
        "N4687 26.3.7.2 [array.cons]/2: "
        "Requires: (is_same_v<T, U> && ...) is true. Otherwise the program is ill-formed.");
    using type = _First;
};

template <class _First, class... _Rest>
array(_First, _Rest...)->array<typename _Enforce_same<_First, _Rest...>::type, 1 + sizeof...(_Rest)>;
#endif // _HAS_CXX17

第二件事是如何工作的?它看起来不像一个类或函数,那么它是什么?

标签: c++c++17

解决方案


推荐阅读