Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: pfc container types do not satisfy the c++20 range concepts (Read 119 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

pfc container types do not satisfy the c++20 range concepts

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?