1- #pragma once
2- #include " array.hpp"
3- #include < bitset>
1+ #pragma once // 千万不要遗漏
2+ #include " array.hpp" // 这句可以没有,但是为了编译器检查方便,还是包含一下吧
3+ #include < bitset> // user::array内部的数据需要利用std::bitset来管理
44namespace user {
55// array类模板特化部分
66template <std::size_t N>
77class array <bool , N>; // 特化的声明
8- template <std::size_t N, std::size_t M>
8+ template <std::size_t N, std::size_t M> // 模板参数与另一个不同,所以它是一个重载
99void swap (array<bool , N>&, array<bool , M>&);
1010template <std::size_t N>
1111class array <bool , N> { // 定义array<bool,N>部分特化
@@ -24,14 +24,14 @@ public:
2424 constexpr const bool & back ()const { return _elem[N - 1 ]; }
2525 constexpr bool empty ()const { return !N; }
2626 constexpr std::size_t size ()const { return N; }
27- void fill (bool ); // 传值比传常量引用更省内存空间
27+ void fill (bool ); // 对于bool来说, 传值比传常量引用更省内存空间
2828 template <std::size_t I, typename U, std::size_t M>
29- friend U& get (array<U, M>&); // 这里不建议把U改成bool ,因为U不是T
29+ friend U& get (array<U, M>&); // 不建议把U改成bool ,因为U不是T
3030 // 声明模板友元,所有的get<U,M>函数实例都是类实例array<bool,N>的友元
3131 template <std::size_t I, typename U, std::size_t M>
3232 friend const U& get (const array<U, M>&);
3333 // 同上
34- template <std::size_t N, std::size_t M> // 模板参数变化,所以它是一个重载
34+ template <std::size_t N, std::size_t M>
3535 friend void swap (array<bool , N>&, array<bool , M>&);
3636 template <typename , std::size_t >
3737 friend class array ;
0 commit comments