Opened 4 years ago

Closed 4 years ago

#870 closed ожидается проверка (задача сдана)

WW #13

Reported by: samoylov.viktor Owned by: Sokolov Viacheslav
Component: WW_array Version: 3.0
Keywords: Cc:

Description


Change History (5)

comment:1 Changed 4 years ago by Sokolov Viacheslav

Type: ожидается проверкаожидаются исправления

24 T data[N] = {};

противоречит

Конструкторы и деструкторы должны вызываться ровно так же, как и в обычном массиве.

30 uint8_t data[static_cast<int>(ceil(N/8.0))] = {};
1) почему int?
2) зачем floating-point операции?
3) как гарантировать, что размер совпадает с тем, который просят в условии?

38 array_bool_proxy& operator=(const array_bool_proxy& other) noexcept;

rvalue стоит либо реализовать, либо явно запретить

52 void fill(const bool& val);

https://godbolt.org/z/buRGSV

на самом деле ко всем методам можно дописать constexpr

7 template<typename T, std::size_t N>
8 const T& my_array<T, N>::operator[](std::size_t index) const noexcept {
9 return data[index];

10 }

assert все же не повредит

55 object &= ((1 << 8) - 1) (1 << index_);
56 object
= (b << index_);

аккуратнее будет использовать static_cast<uint8_t> и поставить assert на значение index. Знаковый сдвиг != беззнаковый сдвиг.

60 template<std::size_t N>
61 auto my_array<bool, N>::array_bool_proxy::operator=(const array_bool_proxy& other) noexcept -> array_bool_proxy& {
62 object &= ((1 << 8) - 1) (1 << index_);
63 object
= ((bool)other << index_);
64 return *this;
65 }

непонятно, зачем дублировать код, если можно просто позвать this->operator=(static_cast<bool>(other));

82 return (data[index/8] >> (index % 8)) & 1;
95 return array_bool_proxy(index % 8, data[index/8]);

[]?

113 for (std::size_t index = 0; index < static_cast<std::size_t>(ceil(N/8.0)); index++) {
114 data[index] = value;
115 }
memset?

comment:2 Changed 4 years ago by samoylov.viktor

Type: ожидаются исправленияожидается проверка
Version: 1.02.0

comment:3 Changed 4 years ago by Sokolov Viacheslav

Type: ожидается проверкаожидаются исправления

static_cast<std::size_t>(N / 8 + static_cast<std::size_t>(N % 8 != 0))
можно было бы вынести в constexpr size_t divideRoundUp8(size_t), но это совсем minor

static_cast имелся в виду не на результат, а на 1 / b. Результат-то и так будет преобразован.

65 template<std::size_t N>
66 constexpr auto my_array<bool, N>::array_bool_proxy::operator=(const array_bool_proxy& other) noexcept -> array_bool_proxy& {
67 this->operator=(static_cast<bool>(other));
68 return *this;
69 }
70
71 template<std::size_t N>
72 constexpr auto my_array<bool, N>::array_bool_proxy::operator=(array_bool_proxy&& other) noexcept -> array_bool_proxy& {
73 std::swap(object, other.object);
74 std::swap(index_, other.index_);
75 return *this;
76 }

с такой rvalue версией неправильно работает x[3] = x[4].

comment:4 Changed 4 years ago by samoylov.viktor

Type: ожидаются исправленияожидается проверка
Version: 2.03.0

comment:5 Changed 4 years ago by Sokolov Viacheslav

Resolution: задача сдана
Status: assignedclosed
Note: See TracTickets for help on using tickets.