libcamera: base: utils: Use size_t for index in utils::enumerate()

The index generated by utils::enumerate() is an iteration counter, which
should thus be positive. Use std::size_t instead of the difference_type
of the container.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
This commit is contained in:
Laurent Pinchart 2021-09-02 04:02:43 +03:00
parent 06e53199c2
commit f9c1a40e21
2 changed files with 7 additions and 7 deletions

View file

@ -246,7 +246,7 @@ private:
public: public:
using difference_type = typename std::iterator_traits<Base>::difference_type; using difference_type = typename std::iterator_traits<Base>::difference_type;
using value_type = std::pair<const difference_type, base_reference>; using value_type = std::pair<const std::size_t, base_reference>;
using pointer = value_type *; using pointer = value_type *;
using reference = value_type &; using reference = value_type &;
using iterator_category = std::input_iterator_tag; using iterator_category = std::input_iterator_tag;
@ -275,7 +275,7 @@ public:
private: private:
Base current_; Base current_;
difference_type pos_; std::size_t pos_;
}; };
template<typename Base> template<typename Base>

View file

@ -77,8 +77,8 @@ protected:
int testEnumerate() int testEnumerate()
{ {
std::vector<int> integers{ 1, 2, 3, 4, 5 }; std::vector<unsigned int> integers{ 1, 2, 3, 4, 5 };
int i = 0; unsigned int i = 0;
for (auto [index, value] : utils::enumerate(integers)) { for (auto [index, value] : utils::enumerate(integers)) {
if (index != i || value != i + 1) { if (index != i || value != i + 1) {
@ -93,12 +93,12 @@ protected:
++i; ++i;
} }
if (integers != std::vector<int>{ 0, 1, 2, 3, 4 }) { if (integers != std::vector<unsigned int>{ 0, 1, 2, 3, 4 }) {
cerr << "Failed to modify container in enumerated range loop" << endl; cerr << "Failed to modify container in enumerated range loop" << endl;
return TestFail; return TestFail;
} }
Span<const int> span{ integers }; Span<const unsigned int> span{ integers };
i = 0; i = 0;
for (auto [index, value] : utils::enumerate(span)) { for (auto [index, value] : utils::enumerate(span)) {
@ -112,7 +112,7 @@ protected:
++i; ++i;
} }
const int array[] = { 0, 2, 4, 6, 8 }; const unsigned int array[] = { 0, 2, 4, 6, 8 };
i = 0; i = 0;
for (auto [index, value] : utils::enumerate(array)) { for (auto [index, value] : utils::enumerate(array)) {