| ||||
| Comment on GotW #94 Solution: AAA Style (Almost Always Auto) by Herb Sutter GotW94: AAA Style (Almost Always Auto) | musingstudio
[…] Sutter’s Guru of the Week article on Almost Always Auto is a tour de force covering everything you always wanted to know about […] Read More »Comment on GotW #7a: Minimizing Compile-Time Dependencies, Part 1 by Herb Sutter
@Gennaro: Yes, I’ll add a note to be clear it’s okay to replace #include with a forward declaration. All: Remember to use for code blocks, or escape those pesky characters using “& l t ;” and “& g t ;”. Sorry, it’s a WordPress thing. Read More »Comment on GotW #7a Solution: Minimizing Compile-Time Dependencies, Part 1 by thokra
I’m aware that this isn’t the topic of this GotW, but one minor detail: shouldn’t More in regards to coding conventions, is there any reason why Comment on GotW #7b: Minimizing Compile-Time Dependencies, Part 2 by Arne Mertz
1) private means nothing except methods (static or non-static) of the class itself, and befriended functions may access the member. befriended functions include free functions declared as friends, as well as methods of classes declared as friends. Comment on GotW #7b: Minimizing Compile-Time Dependencies, Part 2 by John Humphrey
The “class E” declaration appears to have gone missing. Read More »Comment on GotW #7b: Minimizing Compile-Time Dependencies, Part 2 by thefatredguy
Here’s my take on it : 1. When a member (either data or function) is declared as private, only // x.h: sans gratuitous headers // #include <iosfwd> #include <memory> // for shared/unique_ptr // None of A, B, C, or D are templates. // Only A and C have virtual functions. #include "a.h" // class A #include "b.h" // class B class X : public A, private B { public: X( const C& ); virtual ~X(); B f( int, char* ); C f( int, C ); C& g( B ); E h( E ); virtual std::ostream& print( std::ostream& ) const; // might also have to either define or delete copy constructor, // assign operator and move constructor private : struct implementation_details; std::unique_ptr<implementation_details> impl_; }; std::ostream& operator<<( std::ostream& os, const X& x ) { return x.print(os); } In the implementation file : #include <list> #include <iostream> #include <ostream> #include "c.h" #include "d.h" struct X::implementation_details { std::list<C> clist; D d_; }; X::X(const C&) : A(), B(), impl_(new implementation_details()) {} X::~X() {} Its not without any drawbacks though. There’s an extra allocation for each Comment on GotW #7b: Minimizing Compile-Time Dependencies, Part 2 by Alf P. Steinbach
As John Humphrey noted the "class E" declaration appears to have gone missing. Also, there’s still no include guard or #pragma once . Also, the operator<< is still not declared inline . The above are coding errors, ungood in example code (not to mention production code).. And with this new part II question (I’m happy that I didn’t overlook anything for part I) this GOTW is no longer about fixing things. It is now about introducing inefficiences (for PIMPL) and/or a maintainance nightmare (for duplication) alleviate symptoms of ungoodness, which IMHO is misguided. The ungoodness: ungood physical packaging of the code (distribution of code in files), and ungood tools (archaic compiler technology, e.g. with Visual C++ and g++). The physical packaging is too course grained and/or the software design does not properly support physical packaging, iif the headers drag in enough stuff to make a successful build too slow. The tools, well we can’t do much about them, but a reasonable modern approach would be for a compiler to by default compile several C++ translation units in one go, checking each header (except for [assert.h]) only once, Also, for a compiler to not waste time on storing context info in order to be able to continue after error with an avalanche of misleading and outright incorrect messages. nstead, as (IIRC) Turbo C++ did, it should stop at first error, and be taking advantage of that so that it’s fast about it. The archaic tool problem here is so much a pain in the a[censored][censored] that people have, seriously!, proposed to merge all headers and source code into one big file before compiling. They have even described this approach as an “idiom’, which presumably means that in some shops or projects it’s regularly used, and it has a name, which alas I can’t recall ATM. Given that the tools should better be fixed, so that people don’t have to do hazardious things like that! Introducting inefficiences and/or maintainance problems, as this part II of the GOTW is about, is of course an alternative to just suffering build times and/or doing the risky source concatenation thing, but employing these part II techniques negates much of the purpose of using C++ in the first place… Read More » | ||||
| | ||||
| ||||
Monday, August 19, 2013
FeedaMail: Comments for Sutterâs Mill
Subscribe to:
Comments (Atom)