Friday, December 20, 2013

FeedaMail: Comments for Sutter’s Mill

feedamail.com Comments for Sutter's Mill

Comment on GotW #91 Solution: Smart Pointer Parameters by Bret Kuhns

@CS There was a proposal for this for C++1y, but didn’t make it into the draft. I believe the reasoning was that in the presence of `std::shared_ptr` and `std::unique_ptr`, raw points should always be expressed as observing. Unfortunately, your example of legacy code is exactly the reason why this was a bad decision. I would love to see the “worlds dumbest smart pointer” get revisited in the general library TS coming after C++14…

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3514.pdf

Read More »

Comment on GotW #94 Solution: AAA Style (Almost Always Auto) by void*

We have been trying to define a good strategy for the use of auto for a customer’s C++11 guidelines. Researching we found these nice three GotWs about auto. :) Thanks for those!

Trying to consequently use auto for local variables we ran into three situations where it does not work nicely:

  #include <vector>      class foo_t  {  public:     foo_t() {}       foo_t( const foo_t& ) = delete;       void bar() const {}  };      int main()  {     // example 1: doesn't work for pointer types     // auto i_ptr = int*{};       // like this it's fine     typedef int* int_ptr_t;     auto i_ptr_2 = int_ptr_t{};         // example 2: doesn't work for non-copyable classes     // compiles with VS2013, but I think it shouldn't (g++ doesn't like it)     //auto foo = foo_t{};         // example 3: auto does worse than manually written code can     std::vector< foo_t* > foo_ptrs;       // foo is not as const as it could be (only foo_t* const, could be const foo_t* const)     for( const auto foo : foo_ptrs )     {        foo->bar();     }       // better because it's "more" const     for( const foo_t* const foo: foo_ptrs )     {        foo->bar();     }  }  

- The pointer example is an edge case. Probably don’t need this very much in C++-code (and there’s a work around).
- Having non-copyable objects is more relevant though. I regularly see that…probably thanks to Scott Meyers (Effective C++, Item 6: Explicitly disallow the use of compiler-generated functions you do not want).
- The third situations occurs quite often in legacy code and it just runs against Effective C++, Item 3: Use const whenever possible

Any thoughts/comments about these three cases?

Best regards
Wolfgang Petroschka

Read More »
 
Delievered to you by Feedamail.
Unsubscribe

No comments:

Post a Comment