Hi, I was recently developing a component with a context menu. And I wanted to do something like this:
void my_menu::context_command(unsigned int p_index, metadb_handle_list_cref p_data, const GUID &p_caller) {
switch (p_index) {
case CMD1: {
auto to_process = p_data | std::views::filter([](auto item) { /* filter by some interested fields */});
// ...
}
Sadly this is not possible because metadb_handle_list_cref AKA pfc::list_base_t doesn't satisfy the std::ranges::range concept.
range<T> requires a begin() function to return a std::input_or_output_iterator.
And the iterator is required to have an operator++ returning the reference to itself:
https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator
https://en.cppreference.com/w/cpp/iterator/weakly_incrementable
But in pfc the operator++ is implemented as a void function:
namespace pfc {
template<typename arr_t>
class list_const_iterator {
typedef list_const_iterator<arr_t> self_t;
public:
typedef ptrdiff_t difference_type;
typedef typename arr_t::t_item value_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef std::random_access_iterator_tag iterator_category;
list_const_iterator(arr_t* arr, size_t index) : m_arr(arr), m_index(index) {}
void operator++() { ++m_index; } // <--
void operator--() { --m_index; }
So the containers implemented in pfc can't be treated as ranges, nor adapted to views.
Since we've been gradually moving to c++20, would this problem be fixed soon?