Description 目前存在的问题
用户代码的宏定义使用了保留标识符,导致程序非良构不要求诊断。
#ifndef __ARRAY_HPP__
#define __ARRAY_HPP__
使用了不可移植的标准库实现内部头文件。
依赖了标准库实现的扩展(std::exception 的额外构造函数),而这一扩展甚至是不遵从的。
i. 从标准角度来看重写 what 还是有必要的。
struct out_of_range :std::exception
{
out_of_range (const std::string& s) :exception(s.data()) {}// 没必要重写what方法,无所谓,看需求即可,不知道怎么写就看源码实现
};
同上,用户代码的函数声明使用了保留标识符。
[[noreturn]] void _Xran () const {
用户代码依赖了标准库的名为保留标识符的内部函数。同样可能导致程序非良构不要求诊断,虽然目前标准在这里有些不清晰。
std::_Xout_of_range (" invalid array<T, 0> subscript" );
to_array_impl 应该有 mylib:: 前缀,否则可以触发 ADL 并找到其他人声明的 to_array_impl 函数。
template <class T , std::size_t N>
constexpr mylib::array<std::remove_cv_t <T>, N> to_array (T(&& a)[N])
{
return to_array_impl (std::move (a), std::make_index_sequence<N>{});
}
template <typename T, std::size_t N>
constexpr mylib::array<std::remove_cv_t <T>, N>to_array (T(&a)[N]) {
return to_array_impl (std::move (a), std::make_index_sequence<N>{});
}
待实现的部分
get 应该还有另外 3 个重载。
template <std::size_t N, typename Ty>
decltype (auto ) get(const Ty& a) {
return a[N];
}
目前缺少 array 的比较运算符。
i. 个人认为实现为隐藏友元为好,不应照搬标准库。
Reactions are currently unavailable
You can’t perform that action at this time.
目前存在的问题
c-plus-plus/array/array.hpp
Lines 1 to 2 in 02de6c5
c-plus-plus/array/array.hpp
Line 12 in 02de6c5
std::exception的额外构造函数),而这一扩展甚至是不遵从的。i. 从标准角度来看重写
what还是有必要的。c-plus-plus/array/array.hpp
Lines 16 to 19 in 02de6c5
c-plus-plus/array/array.hpp
Line 162 in 02de6c5
c-plus-plus/array/array.hpp
Line 163 in 02de6c5
to_array_impl应该有mylib::前缀,否则可以触发 ADL 并找到其他人声明的to_array_impl函数。c-plus-plus/array/array.hpp
Lines 283 to 292 in 02de6c5
待实现的部分
get应该还有另外 3 个重载。c-plus-plus/array/array.hpp
Lines 271 to 274 in 02de6c5
array的比较运算符。i. 个人认为实现为隐藏友元为好,不应照搬标准库。