Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array.hpp: 各种问题 #2

Open
frederick-vs-ja opened this issue Oct 16, 2023 · 2 comments
Open

array.hpp: 各种问题 #2

frederick-vs-ja opened this issue Oct 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@frederick-vs-ja
Copy link

目前存在的问题

  1. 用户代码的宏定义使用了保留标识符,导致程序非良构不要求诊断。
    #ifndef __ARRAY_HPP__
    #define __ARRAY_HPP__
  2. 使用了不可移植的标准库实现内部头文件。
    #include<xutility>
  3. 依赖了标准库实现的扩展(std::exception 的额外构造函数),而这一扩展甚至是不遵从的。
    i. 从标准角度来看重写 what 还是有必要的。
    struct out_of_range :std::exception
    {
    out_of_range(const std::string& s) :exception(s.data()) {}//没必要重写what方法,无所谓,看需求即可,不知道怎么写就看源码实现
    };
  4. 同上,用户代码的函数声明使用了保留标识符。
    [[noreturn]] void _Xran() const {
  5. 用户代码依赖了标准库的名为保留标识符的内部函数。同样可能导致程序非良构不要求诊断,虽然目前标准在这里有些不清晰。
    std::_Xout_of_range("invalid array<T, 0> subscript");
  6. to_array_impl 应该有 mylib:: 前缀,否则可以触发 ADL 并找到其他人声明的 to_array_impl 函数。

    c-plus-plus/array/array.hpp

    Lines 283 to 292 in 02de6c5

    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>{});
    }

待实现的部分

  1. get 应该还有另外 3 个重载。

    c-plus-plus/array/array.hpp

    Lines 271 to 274 in 02de6c5

    template<std::size_t N, typename Ty>
    decltype(auto) get(const Ty& a) {
    return a[N];
    }
  2. 目前缺少 array 的比较运算符。
    i. 个人认为实现为隐藏友元为好,不应照搬标准库。
@Mq-b
Copy link
Owner

Mq-b commented Oct 16, 2023

我太卢瑟了,之前写的早没考虑这些。🤣🤣🤣

@Mq-b Mq-b added the bug Something isn't working label Oct 16, 2023
@Mq-b
Copy link
Owner

Mq-b commented Oct 16, 2023

然后对于长度为0的处理我直接抄 msvc 因为那个时候一时也没想到用别的方式抛出错误。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants