[cfe-dev] Function accepting rvalue and lvalue references
James Dennett
james.dennett at gmail.com
Tue Oct 2 17:22:34 PDT 2012
On Tue, Oct 2, 2012 at 5:03 PM, Michael Lehn <michael.lehn at uni-ulm.de> wrote:
>
> Assume I have some templated class
>
> template <typename T>
> struct Dummy {
> // ...
> };
>
> and that I want to overload a fucntion 'foo' such that it accepts a lvalue or
> rvalue reference of it. I can do this using some 'IsDummy trait' as follows:
>
> template <typename A>
> std::enable_if<IsDummy<A>::value, void>
> foo(A &&dummy)
> {
> // ....
> }
>
> So this is not the problem. However, I somehow think that for some time a function
> like
>
> template <typename A>
> void
> foo(Dummy<A> &&dummy)
> {
> // ....
> }
>
> was capturing both, lvalue and rvalue reference. Does my memory trick me?
Possibly so: it works for
template <typename A> void foo(A&&)
because A can be deduced as an lvalue ref there (so that A&& is T& for
some T), but not for your case.
-- James
More information about the cfe-dev
mailing list