fw4spl-org / fw4spl

Main repository for fw4spl
30 stars 15 forks source link

Modified dynamicCast method to handle both const and not const parameter #6

Closed fbridault closed 7 years ago

fbridault commented 7 years ago

We have a template method that simplifies a call to std::dynamic_pointer_cast< std::shared_ptr<T> >(). However this method has actually two versions:

  1. for not const pointers: std::shared_ptr<C> dynamicCast(const std::shared_ptr<T>&)
  2. for const pointers : std::shared_ptr<const C> dynamicConstCast(const std::shared_ptr<const T>&)

I find the second version really misleading because one may think it does a std::const_cast<T>(), which means it would remove the const. Moreover this adds a unnecessary complexity since we can write a single function that handle both cases. This is what this pull request proposes to do. I have not replaced every single dynamicConstCast in the code, but I can do it in a second commit if you think it is ok. Otherwise I think it is in both cases better to keep the method for some time until every occurrence is removed in other repositories.