rvalue Questions
5
Solved
I posted this answer: https://stackoverflow.com/a/28459180/2642059 Which contains the following code:
void foo(string&& bar){
string* temp = &bar;
cout << *temp << " @:"...
Emmy asked 12/2, 2015 at 16:54
1
Solved
In the MSVC STL, the implementation of std::apply is as follows:
template <class _Callable, _Tuple_like _Tuple, size_t... _Indices>
constexpr decltype(auto) _Apply_impl(_Callable&& _O...
1
Solved
I have a function that takes a reference to a T*: void f(T *&t);. When I call it with a conditional expression with a throw, f(t == nullptr ? throw "nullptr" : t), the program f...
4
$4.2/1 - "An lvalue or rvalue of type
“array ofN T” or “array of unknown
bound of T” can be converted to an
rvalue of type “pointer to T.” The
result is a pointer to the first
element of the...
Scoutmaster asked 7/9, 2010 at 7:49
1
I try to compile this test code
struct MyData { /*..*/ };
template < typename T >
struct Wrapper
{
T m_value;
operator T const & () const & { return m_value; }
operator T &&a...
Dune asked 28/2, 2023 at 12:19
4
Solved
Consider the below.
#include <string>
using std::string;
string middle_name () {
return "Jaan";
}
int main ()
{
string&& danger = middle_name(); // ?!
return 0;
}
This doesn't...
1
#include <iostream>
int main() {
bool b = true;
std::cout << std::is_same<decltype(!(!b)), bool>::value << "\n";
auto bb = (!(!b));
std::cout << std::i...
Ebby asked 28/9, 2022 at 6:59
7
Is there a way to write a function in C++ that accepts both lvalue and rvalue arguments, without making it a template?
For example, suppose I write a function print_stream that reads from an istre...
1
Solved
I have a function that returns a lowercase string:
constexpr auto string_to_lower_case(const std::string& string) {
return string
| std::views::transform(std::tolower)
| std::views::transfor...
Addi asked 16/6, 2022 at 11:41
1
Solved
After many years of using C++ I realized a quirk in the syntax when using custom classes.
Despite being the correct language behavior it allows to create very misleading interfaces.
Example here:
c...
Trull asked 20/5, 2022 at 6:54
2
Why does the && argument type in the following example not behave as a so-called "universal reference" even though it seems to be in a "deduced context", and instead is ...
3
I am a C++ newbie and I am struggling on the temporaries topic. I don't find anywhere a clear list of all cases in which the compiler will create a temporary. Actually, a few days ago I had in mind...
Featherbedding asked 2/2, 2022 at 17:56
2
Solved
I don't know which C++ standard presented this feature, but I cannot think of any use cases of this.
A member functions with && modifier will only be considered by overload resolution if t...
9
Solved
1
Solved
Consider the following code, it compiles and runs:
#include <iostream>
#include <sstream>
struct Foo {};
void operator>>(std::istream &, Foo) {
}
int main() {
std::stringstre...
1
Solved
Code
#include<iostream>
int main()
{
int a=3;
a++=5;
std::cout<<a;
}
Output (as expected)
[Error] lvalue required as left operand of assignment
1. The post increment operator (a++)...
Protector asked 18/7, 2021 at 16:16
1
Solved
I have the following functions:
void func(void * const &ptr)
{
std::cerr << "const" << std::endl;
}
void func(void * &&ptr)
{
std::cerr << "mutable&q...
Geodynamics asked 26/6, 2021 at 15:56
2
I write this code:
#include <iostream>
using namespace std;
class Foo
{
public:
int a = 0;
Foo()
{
cout << "ctor: " << this << endl;
}
~Foo() {
cout <&...
4
Solved
I wanted to ask why as_const forbids rvalue arguments, according to cppreference.com (i.e. why the Standards folks made it so, not why cppreference.com specifically quoted them on that. And also no...
1
Solved
I recently started learning about rvalues,lvalues, move semantics and I can't understands some conceps like rvalue refs .. why can I assign a value to a rvalue ref like : int&& x = 10;.. do...
Spence asked 3/1, 2021 at 17:22
6
Solved
What is the reasoning behind the naming of "lvalue" and "rvalue" in C/C++?
Quash asked 2/4, 2013 at 13:51
2
Solved
I have a struct F with a function foo that has different implementation whether F is a temporary or not
struct F{
void foo() & { std::cout << "F::foo() &" << std::end...
Preamble asked 14/10, 2020 at 11:28
1
Solved
For function parameters, it is possible to bind an r-value to an l-value const reference.
However, this does not seem to apply to special member function like the copy-constructor, and copy-assignm...
Bacillus asked 13/8, 2020 at 7:44
1
So basically my question is: When should I use an rvalue reference?
In this example, I'm working on a logger class (it just logs things to the console...). I have different functions to log message...
Sync asked 3/6, 2020 at 14:48
2
Solved
#include <utility>
template <typename Container>
decltype(auto) index(Container &&arr, int n) {
return std::forward<Container>(arr)[n];
}
Make a function call :
#inclu...
Soares asked 3/6, 2020 at 5:38
1 Next >
© 2022 - 2025 — McMap. All rights reserved.