pointer that propagates it's modifiers to the value

60 views
Skip to first unread message

Alexey Mamontov

unread,
Aug 22, 2016, 1:54:38 PM8/22/16
to ISO C++ Standard - Future Proposals
The idea is simple. I need to have some member by pointer (using the abstract base class, for example), but I want it to behave absolutely the same as member by value - it must inherit the constantness of this.

Lets call it member_ptr<T> and see what I mean:

T * member_ptr<T>::operator->();
const T * member_ptr<T>::operator->() const;

T & member_ptr<T>::operator*();
const T & member_ptr<T>::operator*() const;

struct B
{
 void f() = 0;
 void f() const = 0;
};
struct S
{
 member_ptr<B> m;
};

S s;
s.m->f(); // void f() is called
const S cs;
cs.m->f(); // void f() const is called

All other modifiers (volatile, rvalue) must be forwarded as well... 

Shahms King

unread,
Aug 22, 2016, 2:11:46 PM8/22/16
to ISO C++ Standard - Future Proposals

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/28cf9d88-64c9-47c4-83f9-46843d869150%40isocpp.org.

Jonathan Coe

unread,
Aug 22, 2016, 4:23:22 PM8/22/16
to std-pr...@isocpp.org


On 22 Aug 2016, at 20:11, Shahms King <shahm...@gmail.com> wrote:


libc++ and libstd++ both have implementations in trunk.

Please let me know if they don't do what you want.

The libc++ implementation should work pretty easily in VS without significant modification.

Reply all
Reply to author
Forward
0 new messages