Opened 8 years ago

Last modified 6 years ago

#11188 new Bugs

can not use repeat(int)[] with std::ref and phoenix::ref

Reported by: vveesskkoo@… Owned by: Joel de Guzman
Milestone: To Be Determined Component: spirit
Version: Boost 1.58.0 Severity: Problem
Keywords: repeat Cc:

Description

Debian libboost-dev 1.55
When trying to compile a rule containing:

qi::repeat(std::ref(_n))[some_action]

the compiler complains: /usr/include/boost/spirit/home/qi/directive/repeat.hpp:88:40: error: use of deleted function ‘std::reference_wrapper<_Tp>::reference_wrapper(_Tp&&) [with _Tp = int]’
T start() const { return type(0); }

In this situation qi:repeat (repeat.hpp:88:40) tries to create an iterator from
std::reference_wrapper<>(rhs_value) which is not possible as a reference is needed!

As a temporary workaround I used the following help type:

template<typename T>
class ref_rhs: public std::reference_wrapper<T> {
    private:
        T   _rhval;
    public:
        using std::reference_wrapper<T>::reference_wrapper; // inherit constructors

        ref_rhs(T&& rhs):
            std::reference_wrapper<T>(_rhval),
            _rhval(rhs)
        {}
};

and the call: qi::repeat(ref_rhs<T>(_n))[] works as expected.

May be qi:repeat should iterate internally with integers rather than with iterators as the documentation says that in the call qi::repeat(_n) _n must be convertible to int anyway.

Change History (1)

comment:1 by anonymous, 6 years ago

Version: Boost 1.55.0Boost 1.58.0
Note: See TracTickets for help on using tickets.