Boost logo

Boost :

From: Rodolfo Lima (rodolfo_at_[hidden])
Date: 2006-11-29 16:43:35

Lambda's return type deduction for a pointer to member action doesn't honour
the object constness.
Regardless of the object constness, the return type is always a non const
reference to the member type.

The following code illustrates the issue:

struct aux
    aux() : b(1) {}
    int b;

struct aux_ptr
    aux_ptr(aux *ptr=NULL) : m_ptr(ptr) {}
    ~aux_ptr() { delete m_ptr; }

    template <class R> R &operator->*(R aux::*m) { return m_ptr->*m; }
    template <class R> const R &operator->*(R aux::*m) const { return
m_ptr->*m; }
    aux *m_ptr;

int main()
    // This compiles nicely
    aux_ptr ptr(new aux());
    cout << (_1->*&aux::b)(ptr) << endl;

    // This fails to compile.
    const aux_ptr cptr(new aux());
    cout << (_1->*&aux::b)(cptr) << endl;
    return 0;

The second part should compile if other_action<member_pointer_action>
honoured _1's constness.

Rodolfo Lima

Boost list run by bdawes at, gregod at, cpdaniel at, john at