From a7d3570e7c2b33d2d9de2696909524b4bc35fc65 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 23 Aug 2022 16:44:28 +0300 Subject: utils: Satisfy LegacyInputIterator with StringSplitter::iterator The StringSplitter::iterator is used with the utils::split() function to iterate over components of a split string. Add the necessary member types expected by std::iterator_trait in order to satisfy the LegacyInputIterator requirement and make the iterator usable in constructors for various containers. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Paul Elder --- include/libcamera/base/utils.h | 6 ++++++ test/utils.cpp | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 889bb4a2..ed88b716 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -170,6 +170,12 @@ public: class iterator { public: + using difference_type = std::size_t; + using value_type = std::string; + using pointer = value_type *; + using reference = value_type &; + using iterator_category = std::input_iterator_tag; + iterator(const StringSplitter *ss, std::string::size_type pos); iterator &operator++(); diff --git a/test/utils.cpp b/test/utils.cpp index 129807a6..58b5a59d 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -276,6 +276,14 @@ protected: return TestFail; } + const auto &split = utils::split(path, ":"); + dirs = std::vector{ split.begin(), split.end() }; + + if (dirs != elements) { + cerr << "utils::split() LegacyInputIterator test failed" << endl; + return TestFail; + } + /* utils::join() with conversion function test. */ std::vector sizes = { { 0, 0 }, { 100, 100 } }; s = utils::join(sizes, "/", [](const Size &size) { -- cgit v1.2.1