nrvo Questions
3
Solved
Is the following C program guaranteed to exit with 0 or is the compiler allowed to identify the objects s and t with one another as is permitted in C++ as the so-called named return value optimizat...
Highspirited asked 27/7 at 21:25
1
Solved
GCC 14 introduced a new -Wnrvo flag:
New -Wnrvo warning, to warn if the named return value optimization is not performed although it is allowed by [class.copy.elision]. See the manual for more inf...
Mesothelium asked 13/5 at 8:52
3
In many cases, I would like to create a new instance of data and return it to the API caller.
I learned that unique_ptr/shared_ptr can be used for factory pattern (for example, Factory pattern us...
Downtoearth asked 5/3, 2020 at 13:16
3
Solved
i was fooling around with the following code and got different results using my visual studio 2017 application and two different online compilers. in release mode visual studio does elide the copy/...
Quassia asked 12/2, 2018 at 15:6
2
Solved
This question is a slight variant on a related question shown here.
In C++17 I have a local variable that I want to be const to demonstrate it is unmodified once created per Scott Meyers Effective...
Xmas asked 17/5, 2019 at 23:23
4
A function needs to return two values to the caller. What is the best way to implement?
Option 1:
pair<U,V> myfunc()
{
...
return make_pair(getU(),getV());
}
pair<U,V> mypair = myfun...
2
Solved
I expected to see copy elision from Named Return Value Optimization (NRVO) from this test program but its output is "Addresses do not match!" so NRVO didn't happen. Why is this?
// test.c...
Kampmann asked 19/7, 2020 at 21:24
1
Solved
I recently discovered std::optional as a way to improve the clarity of my code, especially for return value of functions. However I had questions about its impact on performance. More specifically ...
Mandrill asked 15/11, 2019 at 21:39
1
Solved
Consider the following piece of code:
std::vector<int> Foo() {
std::vector<int> v = Bar();
return v;
}
return v is O(1), since NRVO will omit the copy, constructing v directly in t...
Jephthah asked 16/6, 2018 at 0:24
1
Solved
I am confused with regards how do compiler and linker deal with the fact that requirements on the caller of the function differ depending on if the function uses RVO or NRVO.
This could be my misu...
3
Solved
Consider something like this:
typedef std::unordered_multiset<int> Set;
typedef std::set<Set> SetOfSets;
SetOfSets somethingRecursive(SomeType somethingToAnalyze) {
Set s;
// ...
/...
1
Solved
EDIT: it is NOT a duplicate because this question asks about a compiler's decision in O0.
It is said here that Name Return Value Optimization (NRVO) is an optimization many compiler support....
1
Solved
I think it should, because it's important for correctness. However, I'm surprised to see Clang's output. Consider the code below:
#include <iostream>
struct S
{
int i;
S(int i) : i(i) {}...
2
Solved
Let's say we have this situation
std::string v_1()
{
return "name";
}
std::string test = v_1();
Is RVO applied here? I think that the answer is no, because one the rules to apply RVO is: "If a ...
1
Solved
I always thought that it's good to have const locals be const
void f() {
const resource_ptr p = get();
// ...
}
However last week I watched students that worked on a C++ exercise and that wond...
Hendecasyllable asked 4/7, 2016 at 20:32
1
struct X {
void * a;
void * b;
};
X foo( void * u, void * v);
foo() is implemented in assembler (i386)
address of return value of type X is passed as hidden parameter to foo()
if test code is...
Scarify asked 2/11, 2015 at 10:18
2
Solved
I'm trying to reason why a reasonably good C++ 11 compiler (clang) is not optimizing this code, and wondering if anybody here has opinions.
#include <iostream>
#define SLOW
struct A {
A() ...
Blacking asked 18/12, 2013 at 4:58
2
NRVO is not applied when I run this code in VS2010.
#include <stdio.h>
class A
{
public:
A() { printf( "I am in constructor\n" ); }
A(const A& a) { printf( "I am in copy constructor...
Resentful asked 16/4, 2013 at 13:32
1
Solved
Let's say I have the function
#include <string>
std::string const foo()
{
std::string s = "bar";
return s;
}
int main()
{
std::string t = foo();
}
Can a compiler perform (named) retur...
Sixfooter asked 20/1, 2013 at 22:20
1
Solved
I've been reading about (N)RVO and would like one, complete scenario description. I hope this question will serve other C++ -learners to clarify their ideas.
Suppose this scenario:
string get_str...
Hailey asked 20/10, 2012 at 9:51
6
Solved
I can't get my head around RVO (and NRVO) definition because of multiple questions like this one that to me look assuming that RVO omits a copy constructor. Now according to 12.8.15
In such case...
Bedroom asked 24/4, 2012 at 6:16
6
The following code calls the destructor 4 times:
#include<iostream>
using namespace std;
class A{
public:
A(){cout<<"A"<<endl;}
~A(){cout<<"~A"<<endl;}
A f(){cou...
1
© 2022 - 2024 — McMap. All rights reserved.