Opened 4 years ago

Closed 4 years ago

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

WW #13

Reported by: Карнаухов Кирилл 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: ожидается проверкаожидаются исправления

16 my_array(const my_array& other);
17 my_array(my_array&& other) noexcept;
19 my_array& operator=(const my_array& other);
20 my_array& operator=(my_array&& other) noexcept;

лучшая реализация этих методов - это просто их не декларировать / написать = default.

38 constexpr static std::size_t SIZE = (N + COMPRESSION - 1) / COMPRESSION;

может переполниться при большом N

45 proxy& operator=(const proxy& other);
rvalue версию стоит либо реализовать, либо явно удалить

47 proxy operator=(bool new_value);
pxoy&?

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

40 template <typename T, std::size_t N>
41 const T& my_array<T, N>::at(std::size_t index) const {
42 if (index >= N) {
43 throw std::out_of_range("Out of range.");
44 }
45 return data[index];
46 }
47
48 template <typename T, std::size_t N>
49 T& my_array<T, N>::at(std::size_t index) {
50 if (index >= N) {
51 throw std::out_of_range("Out of range.");
52 }
53 return data[index];
54 }

можно указать, по какому индексу было обращение

55
56 template <typename T, std::size_t N>
57 const T& my_array<T, N>::operator[](std::size_t index) const noexcept{
58 return data[index];
59 }
60
61 template <typename T, std::size_t N>
62 T& my_array<T, N>::operator[](std::size_t index) noexcept{
63 return data[index];
64 }

assert будет полезен

85 template <std::size_t N>
86 auto my_array<bool, N>::proxy::operator=(const proxy& other) -> proxy& {
87 value = other.value;
88 index = other.index;
89 return *this;
90 }

с такой реализацией не работает a[3] = a[4] (делает не то, что нужно)

104 template <std::size_t N>
105 my_array<bool, N>::my_array() noexcept {
106 for (size_t i = 0; i < SIZE; i++) {
107 data[i] = 0;
108 }
109 }
по условию этого не требовалось? В любом случае лучше fill(false)

177 template <std::size_t N>
178 void my_array<bool, N>::fill(bool value) noexcept {
179 char bunch_value = (value ? (1 << COMPRESSION) - 1 : 0);
180 for (size_t i = 0; i < SIZE; i++) {
181 data[i] = bunch_value;
182 }
183 }
лучше memset

95 value |= (std::size_t(new_value) << index);

146 return (data[index / COMPRESSION] & (1 << (index % COMPRESSION)));
лучше делать не c-style cast / оставить тип int, а делать явный static_cast<char>

также корректнее использовать не char, а uint8_t: битовая арифметика для беззнаковых и знаковых типов отличается. Для беззнаковых она "интуитивная".

comment:2 Changed 4 years ago by Карнаухов Кирилл

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

comment:3 Changed 4 years ago by Sokolov Viacheslav

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

59 constexpr explicit my_array<bool, N>() noexcept;
60 ~my_array<bool, N>() = default;
61
62 constexpr my_array<bool, N>(const my_array<bool, N>& other) noexcept;
63 constexpr my_array<bool, N>(my_array<bool, N>&& other) noexcept;
64
65 constexpr my_array<bool, N>& operator=(const my_array<bool, N>& other) noexcept;
66 constexpr my_array<bool, N>& operator=(my_array<bool, N>&& other) noexcept; 59 constexpr explicit my_array<bool, N>() noexcept;
60 ~my_array<bool, N>() = default;
61
62 constexpr my_array<bool, N>(const my_array<bool, N>& other) noexcept;
63 constexpr my_array<bool, N>(my_array<bool, N>&& other) noexcept;
64
65 constexpr my_array<bool, N>& operator=(const my_array<bool, N>& other) noexcept;
66 constexpr my_array<bool, N>& operator=(my_array<bool, N>&& other) noexcept;

можно просто my_array

96 return (value & (1 << index));
знаковый сдвиг. Можно value >> index & 1u

140 return static_cast<bool>(data[index / COMPRESSION] & (1 << (index % COMPRESSION)));
155 return static_cast<bool>(data[index / COMPRESSION] & (1 << (index % COMPRESSION)));
176 uint8_t bunch_value = (value ? (1 << COMPRESSION) - 1 : 0);
знаковый сдвиг

comment:4 Changed 4 years ago by Карнаухов Кирилл

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.