Skip to content

Classic: Fixed position_iterator forming reference to local - #422

Merged
Kojoley merged 1 commit into
boostorg:developfrom
Kojoley:classic-fix-position_iterator-returns-reference-to-local
Nov 23, 2018
Merged

Classic: Fixed position_iterator forming reference to local#422
Kojoley merged 1 commit into
boostorg:developfrom
Kojoley:classic-fix-position_iterator-returns-reference-to-local

Conversation

@Kojoley

@Kojoley Kojoley commented Nov 23, 2018

Copy link
Copy Markdown
Collaborator

When underlying iterator returns by value the corresponding position_iterator was providing iterator_adaptor with a reference type what lead to returning a reference to a local variable in dereference operator.

Made a custom trait because it is a way more elegant than:

    typedef typename boost::mpl::if_c<
        boost::is_reference<reference>::value,
        typename boost::add_reference<
            typename boost::add_const<
                typename boost::remove_reference<reference>::type
            >::type
        >::type,
        typename boost::add_const<reference>::type
    >::type const_reference_type;

Fixes https://svn.boost.org/trac10/ticket/9737.

When underlying iterator returns by value the corresponding position_iterator
was providing iterator_adaptor with a reference type what lead to returning
a reference to a local variable in dereference operator.

Made a custom trait because it is a way more elegant than:
```cpp
    typedef typename boost::mpl::if_c<
        boost::is_reference<reference>::value,
        typename boost::add_reference<
            typename boost::add_const<
                typename boost::remove_reference<reference>::type
            >::type
        >::type,
        typename boost::add_const<reference>::type
    >::type const_reference_type;
```

Fixes https://svn.boost.org/trac10/ticket/9737.
@djowel

djowel commented Nov 23, 2018

Copy link
Copy Markdown
Collaborator

wonderful!

@Kojoley
Kojoley merged commit 0bfc421 into boostorg:develop Nov 23, 2018
@Kojoley
Kojoley deleted the classic-fix-position_iterator-returns-reference-to-local branch November 23, 2018 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants