HydrogenAudio

Hosted Forums => foobar2000 => Development - (fb2k) => Topic started by: pnck on 2024-04-25 01:09:13

Title: pfc container types do not satisfy the c++20 range concepts
Post by: pnck on 2024-04-25 01:09:13
Hi, I was recently developing a component with a context menu. And I wanted to do something like this:
Code: [Select]
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:
Code: [Select]
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?