avoid rvalue template deduction
I have a class template that wants to take an iterator type with an auto deduction from the constructor.
template <typename T>
struct Foo {
Foo(T a);
}
If I have the following, T
will be std::vector<int>::iterator
:
std::vector<int> vector;
auto I = vector.begin();
auto ptr = new Foo(I);
However, if I pass rvalue, T
will be std::vector<int>::iterator&&
std::vector<int> vector;
auto ptr = new Foo(vector.begin());
How can I force each deduction to remove the &&
? I simply just want to keep the iterator type where the copy is cheap.
Thanks.
However, if I pass rvalue,
T
will bestd::vector<int>::iterator&&
No. T
is not a reference type (does not have &&
), so it will still be deduced as std::vector<int>::iterator
, your assumption is incorrect.