On Sat, 2016-03-19 at 20:10 +0000, Matthew Brincke wrote: > > the "cast" from non-const to const does compiler for free. Using > > 1. In this case, it doesn't. Without explicitly giving it, the compiler > would insert a call to the same method it's in, leading to endless > recursion. So the cast on "this" is needed to call the correct method. > > > const_cast() only points to a wrong API design (if you work with a > > const object, but want to modify its content (state), then you > > shouldn't work with the const object at the first place). > > The 'const' is also a hint for the API user, that the > > > function/pointer/whatever is meant for read-only purposes. > > The const object in question here isn't API-user-provided and also not > coming from a method in another class, so this doesn't apply, IMO, > because the object is only (cast to, reason see above) const to call the > the same method, but with "const" qualification (to avoid duplication). > Any assumptions the called code makes could be remedied in the caller > (it's in the same class), such as setting a "dirty" flag, but I don't see any.
My main point is that you use const_cast<> to remove the 'const' flag on a const object. That's usually a bad idea, maybe forced by bad API. The code duplication of 3 x ~6 lines of code is really nothing significant, with compare to overusing 'const' "attribute". > They are currently, but won't be for long if my next patch about > dynamic_cast is acceptable. (I'm planning getting rid of most old- > style casts in PoDoFo). I suggest you, before doing any significant changes, to announce them beforehand and let the maintainers (not me) know earlier, discuss with them (not me) the changes and eventually wait for their (not my) agreement of such changes, thus you'll not waste your time with something what might not be accepted for whatever reason. The advantage is that you can get opinions from anyone on the list, before actually doing anything. Bye, zyx P.S.: Clean ups are fine, surprises not that much (my opinion). -- http://www.litePDF.cz i...@litepdf.cz ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 _______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users