Linked Questions

114 votes
3 answers
23k views

What are the implications of the voted in C++17 evaluation order guarantees (P0145) on typical C++ code? What does it change about things like the following? i = 1; f(i++, i) and std::cout << f(...
Johan Lundberg's user avatar
122 votes
5 answers
18k views

The output of this program: #include <iostream> class c1 { public: c1& meth1(int* ar) { std::cout << "method 1" << std::endl; *ar = 1; return *this; ...
Moises Viñas's user avatar
75 votes
3 answers
5k views

I have some (C++14) code that looks like this: map<int, set<string>> junk; for (int id : GenerateIds()) { try { set<string> stuff = GetStuff(); junk[id] = stuff; ...
jma's user avatar
  • 3,799
18 votes
4 answers
6k views

map<int, int> mp; printf("%d ", mp.size()); mp[10]=mp.size(); printf("%d\n", mp[10]); This code yields an answer that is not very intuitive: 0 1 I understand why it happens - the left side of ...
akrasuski1's user avatar
22 votes
1 answer
2k views

#include <iostream> int& addOne(int& x) { x += 1; return x; } int main() { int x {5}; addOne(x) = x; std::cout << x << ' ' << addOne(x); } I'm ...
Dappster's user avatar
  • 322
20 votes
2 answers
909 views

Today I came across some code that exhibits different behavior on clang++ (3.7-git), g++ (4.9.2) and Visual Studio 2013. After some reduction I came up with this snippet which highlights the issue: #...
Fredrik Axelsson's user avatar
8 votes
3 answers
1k views

The following code works in clang++, but crashes spectacularly in g++ #include<vector> #include<iostream> template<class Iterator> double abs_sum(double current_sum, Iterator it, ...
LKlevin's user avatar
  • 361
2 votes
4 answers
2k views

I am a beginner student in c++ and there is one thing I cannot understand when working with character arrays: So, I know that pointers are essentially variables that "point" to the memory address of ...
mountainkingRune's user avatar
9 votes
2 answers
260 views

Is there a way in C and C++ to cause functions returning void to be evaluated in unspecified order? I know that function arguments are evaluated in unspecified order so for functions not returning ...
Praxeolitic's user avatar
  • 24.4k
7 votes
2 answers
276 views

Let's say we have class A: class A { public: A& func1( int ) { return *this; } A& func2( int ) { return *this; } }; and 2 standlone functions: int func3(); int func4(); now in this ...
Slava's user avatar
  • 44.4k
3 votes
1 answer
507 views

I've read from Order of evaluation, and I don't understand it well. Does the order mean the execution order in run time or just the logic order in the source code? Let's see a code snippet as below: ...
ricky's user avatar
  • 2,128
8 votes
1 answer
323 views

I have found code below in "The C++ programming language, 4th edition", chapter 17.5.1.3 struct S2 { shared_ptr<int> p; }; S2 x {new int{0}}; void f() { S2 y {x}; // ‘‘...
Fabrice Jammes's user avatar
1 vote
1 answer
658 views

Given a fixed-sized array A of objects, suppose a much smaller subset of these objects meet a certain criteria B. There are three tasks I want to complete with approximately equal frequency: I want ...
EllipticalInitial's user avatar
2 votes
1 answer
186 views

Suppose I have a function foo(x, y, z) that is invariant w.r.t. all permutations of its arguments. I also have an iterator it, such that the iterators it, it + 1 and it + 2 can be dereferenced. Is it ...
Evg's user avatar
  • 26.6k
0 votes
1 answer
67 views

This is my first question on this forum, and i expect this will not be a dummy one. I searched the answer everywhere but can't find it. Feel free to redirect me if the question is already answered ...
CreatorOfMoon's user avatar