universal-reference Questions
1
Solved
I thought universal reference (T&&) is supposed to take any kind of reference. But the following doesn't work.
I run into this problem when I try to be const-correct in a library that I am...
Dryden asked 15/11, 2016 at 20:50
2
Solved
An argument to this function will bind to an rvalue reference:
void f(int && i);
However, an argument to this function will bind to either an rvalue or an lvalue reference:
template &...
Nester asked 17/9, 2016 at 22:24
0
I've stumbled upon Scott Mayers article on universal references, link.
From what I understood universal reference, that is some type T&& can mean an rvalue or lvalue type in different cont...
Astrakhan asked 1/1, 2016 at 14:6
1
Solved
I know that if a variable or parameter is declared to have type T&& for some deduced type T, that variable or parameter is widely called a universal reference.
The term universal reference...
Dannadannel asked 24/11, 2015 at 21:46
5
Solved
I have a function which sorts two vectors with the first of them as ordering criterion. Its signature is
template<typename A, typename B>
void sort(A&& X, B&& Y)
{
..
}
Th...
Geoffreygeoffry asked 22/9, 2015 at 15:20
3
Solved
I looked recently at this video explaining the ideas of concepts lite in C++, which are likely to appear this year as a TS. Now, I also learned about universal references/forwarding references (as ...
Naturalism asked 21/3, 2015 at 11:39
1
Solved
Suppose somewhere in my code is a function foo with a universal reference parameter, which I cannot change:
template<typename T>
auto foo(T&& t) { std::cout<<"general version"&...
Mott asked 20/8, 2015 at 14:51
2
I'm struggling to understand what exactly happens when passing a reference-to-function to a function as a universal reference (what type is being deduced). Let's suppose we have a function foo that...
Leavetaking asked 29/6, 2015 at 20:58
3
Solved
I'm curious if, in general, you are to use T&& (universal reference) instead of the classic T const& (l-value reference) for templated function parameters starting with C++11. What I'm ...
Oralla asked 8/6, 2015 at 23:54
2
Solved
Example:
template <typename T>
class Bar
{
public:
void foo(T&& arg)
{
std::forward<T>(arg);
}
};
Bar<int> bar;
bar.foo(10); // works
int a{ 10 };
bar.foo(a); // ...
Horatius asked 1/6, 2015 at 8:59
1
I've been trying to use a template member function to set a value inside of my class. I wanted to use a universal reference so that I could accept any variant of the correct type (e.g. T, T&, T...
Macilroy asked 21/2, 2015 at 8:13
1
Assuming my current rule when programming with range-based loops says
Use for(auto const &e :...) or for(auto &e:...) when possible over for(auto a: ...).
I base this on my own e...
Apomorphine asked 18/11, 2014 at 9:59
1
Solved
The following definition of a min function
template <typename T, typename U>
constexpr auto
min(T&& t, U&& u) -> decltype(t < u ? t : u)
{
return t < u ? t : u;
}
...
Pimbley asked 14/10, 2014 at 7:21
6
Solved
Problem
Let's assume a function func that takes any container in the form Container<Type, N, Args...> (that is a container that takes as first template argument a type and as second an std::...
Guardianship asked 26/7, 2014 at 16:32
1
Solved
Why does rvalue optimization not occur in classes with constructor with universal reference arguments?
http://coliru.stacked-crooked.com/a/672f10c129fe29a0
#include <iostream>
template<...
Headpiece asked 24/7, 2014 at 4:27
1
Solved
Scott Meyers says (for parameters to function templates):
Universal references can only occur in the form "T&&"! Even the
simple addition of a const qualifier is enough to disable the
...
Tupler asked 15/7, 2014 at 16:0
2
Solved
Consider this snippet of code, which uses the common idiom of having a function template construct an instance of a class template specialized on a deduced type, as seen with std::make_unique and s...
Stenotypy asked 30/6, 2014 at 19:15
2
Solved
Before c++11, I used to write code like this:
// Small functions
void doThingsWithA(const A& a)
{
// do stuff
}
void doThingsWithB(const B& b)
{
// do stuff
}
void doThingsWithC(const ...
Purgatorial asked 19/6, 2014 at 0:17
1
Solved
Consider the two following:
template <class Function>
void apply(Function&& function)
{
std::forward<Function>(function)();
}
and
template <class Function>
void apply...
Terenceterencio asked 25/4, 2014 at 16:34
4
Solved
As far as I know, in C++11, universal reference should always be used with std::forward, but I am not sure of what kind of problem can occur if std::forward is not used.
template <T>
void f(...
Chlorinate asked 25/4, 2014 at 6:54
3
Solved
Let's say I have this function:
bool f(int&& one, int&& two) { }
If I attempt to call it with this code:
int x = 4;
f(x, 5);
the compiler will complain that it cannot convert...
Encomium asked 3/10, 2013 at 7:24
1
Solved
When I consider the two following overloads:
template <class... T> void f(const T&... x);
template <class T> void f(const T& x);
I have the guarantee that f(x) will always ca...
Odoacer asked 16/8, 2013 at 2:20
1
Solved
While playing with universal references, I came across this instance where clang and gcc disagree on overload resolution.
#include <iostream>
struct foo {};
template<typename T>
void...
Triciatrick asked 31/7, 2013 at 19:31
2
Solved
I have a function which can accept any type by universal reference, and would like to overload it for specific types (some of which are templated themselves, although I don't think that's important...
Akkad asked 22/5, 2013 at 14:51
4
Solved
auto&& mytup = std::make_tuple(9,1,"hello");
std::get<0>(mytup) = 42;
cout << std::get<0>(mytup) << endl;
Is there a copy/move involved (without RVO) when retu...
Sublapsarianism asked 13/2, 2013 at 8:14
1 Next >
© 2022 - 2024 — McMap. All rights reserved.