[Feature request] Consider adding support of reference proxy

Open
#48 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp
Domain
tooling

Research direction

Read the iterator_facade documentation linked in the issue and review the continuation from issue 47 to understand the iterator-category deduction rules. Define what support for RandomAccess iterators with proxy references should mean, including whether a proxy tag is needed, and verify that the resulting API no longer requires manually overriding iterator_category.

Written by the indexing model from the issue text.

Description

Continuing https://github.com/boostorg/iterator/issues/47.
Currently, iterator_facade does not allow to have RandomAcess iterator with reference proxy (aka std::vector<bool>::iterator::reference) .

It looks like that the only thing that prevent this - is iterator-category deduction/override rules https://www.boost.org/doc/libs/1_68_0/libs/iterator/doc/iterator_facade.html :

iterator-category(C,R,V) :=
   if (C is convertible to std::input_iterator_tag
       || C is convertible to std::output_iterator_tag
   )
       return C

   else if (C is not convertible to incrementable_traversal_tag)
       the program is ill-formed

   else return a type X satisfying the following two constraints:

      1. X is convertible to X1, and not to any more-derived
         type, where X1 is defined by:

           if (R is a reference type
               && C is convertible to forward_traversal_tag)
           {
               if (C is convertible to random_access_traversal_tag)
                   X1 = random_access_iterator_tag
               else if (C is convertible to bidirectional_traversal_tag)
                   X1 = bidirectional_iterator_tag
               else
                   X1 = forward_iterator_tag
           }
           else
           {
               if (C is convertible to single_pass_traversal_tag
                   && R is convertible to V)
                   X1 = input_iterator_tag
               else
                   X1 = C
           }

      2. category-to-traversal(X) is convertible to the most
         derived traversal tag type to which X is also
         convertible, and not to any more-derived traversal tag
         type.

The simplest solution for now, seems to override manually iterator_category in Derived class.


Maybe add some proxy tag? Like:

class node_iterator
	: public boost::iterator_facade
	  <
		node_iterator
		, std::pair<int, int>
		, boost::bidirectional_traversal_tag
		, boost::iterator_facade::proxy_reference<std::pair<int, int>>
	  >

And do not downgrade iterator-category, if proxy_reference occurs.

Dominant language
C++
Stars
23
Forks
70
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/iterator

All issues in boostorg/iterator

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.