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? Was it

a compiler bug (I am not sure whether I was using gcc or clang)?

Cheers,

Michael

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

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

Yes, that makes sense. Thanks!

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.

Additional info for your sanity:

As originally proposed,

template <typename A>

void

foo(Dummy<A> &&dummy)

{

// ....

}

did bind to both lvalue and rvalue Dummy<A>. Somewhere around 2009/2010 the committee changed the rules so that it would only bind to rvalue Dummy<A>. You may have had experience with a compiler implementing the previous rules.

Howard

This gem [1] is a well written and informative article on this topic.

I highly recommend reading it.

[1]. http://blogs.msdn.com/b/vcblog/archive/2009/02/03/rvalue-references-c-0x-features-in-vc10-part-2.aspx

-- Sean Silva