Questions tagged [gotw]

Related to Herb Sutter's "Guru of the Week" C++ programming challenges.

17 questions
39
votes
2 answers

C++'s most vexing parse again

Taken directly from http://herbsutter.com/2013/05/09/gotw-1-solution/ While widget w(); is clear for me, I have no idea how can the below code be a function declaration? // same problem (gadget and doodad are types) // widget w( gadget(), doodad()…
Yanko
  • 774
  • 7
  • 15
22
votes
3 answers

For a vector, why prefer an iterator over a pointer?

In Herb Sutter's When Is a Container Not a Container?, he shows an example of taking a pointer into a container: // Example 1: Is this code valid? safe? good? // vector v; // ... char* p = &v[0]; // ... do something with *p…
user5360395
  • 229
  • 2
  • 4
22
votes
2 answers

Use cases for final classes

I was reading comments on Herb Sutter's Guru of the Week redux about virtual functions, and finally saw him mentioning this: [...] “uses of final are rarer” – well, they sort of are. I don’t know of many, and during standardization Bjarne…
Morwenn
  • 19,202
  • 10
  • 89
  • 142
21
votes
2 answers

Does the GotW #101 "solution" actually solve anything?

First read Herb's Sutters GotW posts concerning pimpl in C++11: GotW #100: Compilation Firewalls (Difficulty: 6/10) GotW #101: Compilation Firewalls, Part 2 (Difficulty: 8/10) I'm having some trouble understanding the solution proposed in GotW…
Ben Voigt
  • 260,885
  • 36
  • 380
  • 671
11
votes
2 answers

C++11 type deduction vs const char *

In GotW 94, Herb Sutter draws a distinction between the "classic C++" declaration const char* s = "Hello"; and the "modern" style auto s = "Hello"; He tells us that there's a "subtle difference in the type of s, where the auto style is more…
user2862505
  • 241
  • 2
  • 8
8
votes
2 answers

Understanding of Guru of the Week #67: Double or Nothing

Recently, I was reading the post: Double or Nothing from GOTW by Herb Sutter I am a little confused with the explanation of the following program: int main() { double x = 1e8; while( x > 0 ) { --x; } } Assume that…
taocp
  • 22,020
  • 6
  • 46
  • 60
6
votes
4 answers

A example in Gotw 67

There is a example in http://www.gotw.ca/gotw/067.htm int main() { double x = 1e8; //float x = 1e8; while( x > 0 ) { --x; } } When you change the double to float, it's a infinite loop in VS2008. According to the Gotw…
Gob00st
  • 5,279
  • 6
  • 40
  • 69
6
votes
3 answers

Why initialize unique_ptr with a make_unique call?

Taken from: http://herbsutter.com/2013/05/22/gotw-5-solution-overriding-virtual-functions/ Why should we write: auto pb = unique_ptr{ make_unique() }; Instead of just: auto pb = make_unique(); My only guess is that if we…
Yanko
  • 774
  • 7
  • 15
3
votes
2 answers

What the author is trying to say in GotW #53?

This pseudo-code was obtained from GotW #53 under the subtitle "A Not-So-Good Long-Term Solution". I've been trying to understand for a few hours already what the author is saying, specially in relation to the comment starting with "// error:…
Wake up Brazil
  • 3,341
  • 8
  • 16
3
votes
3 answers

Why not resize and clear works in GotW 54?

Referring to article Gotw 54 by HerbSutter, he explains about The Right Way To "Shrink-To-Fit" a vector or deque and The Right Way to Completely Clear a vector or deque Can we just use container.resize() and container.clear() for the above…
yesraaj
  • 42,284
  • 65
  • 185
  • 246
2
votes
2 answers

Why is this type incomplete when using the PIMPL idiom?

I'm using the PIMPL idiom, and specifically I'm using the template provided from this post. Given the set of classes below and compiling with VS2015 Update 3, I'm getting compile errors: Error C2027 use of undefined type 'C::C_impl' (compiling…
Patrick Quirk
  • 21,498
  • 1
  • 51
  • 85
2
votes
2 answers

Reason for C++ IntAtomicGet, GotW

In the GotW article #45, Herb states the following: void String::AboutToModify( size_t n, bool bMarkUnshareable /* = false */ ) { if( data_->refs > 1 && data_->refs != Unshareable ) { /* ... etc. ... */ This if-condition is not…
mkobierski
  • 59
  • 3
1
vote
2 answers

gotw 80 syntax - initialisation in parameter list

Gotw 80 includes the following example: // Example 1 // #include using namespace std; class A { public: A( const string& s ) { /* ... */ } string f() { return "hello, world"; } }; class B : public A { …
Trent
  • 2,176
  • 2
  • 31
  • 47
1
vote
1 answer

What does "It doesn’t work for references that are members of objects" means in GotW #88?

Herb Sutter: Effective Concurrency: Use Lock Hierarchies to Avoid DeadlockEffective Concurrency: Break Amdahl’s Law! » GotW #88: A Candidate For the “Most Important const” 2008-01-01 by Herb Sutter A friend recently asked me whether Example…
陳 力
  • 4,063
  • 1
  • 18
  • 41
1
vote
1 answer

How can I implement "op" in terms of "op=" in a CRTP base class?

Herb Sutter's Guru of the Week #4, "Class Mechanics", teaches that the "a op b" form of an overloaded operator should be implemented in terms of the "a op= b" form (see point #4 in the solutions). As an example, he shows how do to this for the +…
HighCommander4
  • 44,537
  • 22
  • 112
  • 180
1
2