[Dune-devel] GridFactory returns std::unique_ptr

Simon Praetorius simon.praetorius at tu-dresden.de
Fri Jun 25 09:11:13 CEST 2021


Dear Dune developers,

In the year 2017 (it might have been in a developer meeting) we decided 
to "smoothly" transition from raw pointers in GridFactory::createGrid() 
towards std::unique_ptr. This transition was done, by introducing an 
intermediate representation, called ToUniquePtr that is actually a 
std::unique_ptr that additional gives a deprecation warning in case this 
type is converted into a raw pointer. This made it possible to have user 
code still working, but with this additional warning so that users have 
enough time to adopt their code.

On the library site, the GridFactory implementations for own grids need 
to handle these changes in the return type of createGrid() directly, 
since otherwise the interface for GridFactories is not fulfilled.

Now, finally, we want to drop this intermediate representation (or 
better: deprecate its usage). For user code this should not change 
anything except that now a cast to a raw pointer does not work anymore. 
Since this is deprecated since 4 years it can be expected that user code 
is adopted.

We propose in 
https://gitlab.dune-project.org/core/dune-common/-/merge_requests/912 to 
replace the class ToUniquePtr with an alias template that directly 
defines the std::unique_ptr. If you have an own GridFactory 
implementation for some grid type, you will get a deprecation warning if 
you use that type alias, but the code should still work fine.

The proper fix to remove this deprecation warning is to return directly 
std::unique_ptr:

template <class GridType>
std::unique_ptr<GridType> GridFactory<GridType>::createGrid () override;

If you want to support multiple dune releases in a grid implementation, 
you might need to consider three cases now:

#if DUNE_VERSION_LT(DUNE_COMMON, 2, 7)
// no include needed
#elif DUNE_VERSION_LT(DUNE_COMMON, 2, 8)
#include <dune/common/to_unique_ptr.hh>
#else
#include <memory>
#endif

// ...

#if DUNE_VERSION_LT(DUNE_COMMON, 2, 7)
GridType* createGrid () override;
#elif DUNE_VERSION_LT(DUNE_COMMON, 2, 8)
ToUniquePtr<GridType> createGrid () override;
#else
std::unique_ptr<GridType> createGrid() override;
#endif

We would like to include this change in the Dune 2.8 release. 
Additionally I would try to update GridFactory implementations in core, 
staging and extension modules to have this proper return type. Then, 
hopefully in the next release, we can get rid of this intermediate type 
ToUniquePtr completely.

If you have any remarks or see any overlooked complication, please 
comment in the merge request above. At beginning of next week I want to 
merge this, so that there is enough time to update all the other modules 
before the feature freeze date.

Best regards,
Simon

-- 
Dr. Simon Praetorius
Technische Universität Dresden
Institute of Scientific Computing
phone: +49 351 463-34432
mail: simon.praetorius at tu-dresden.de
web: https://tu-dresden.de/mn/math/wir/das-institut/beschaeftigte/simon-praetorius

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20210625/25773a70/attachment.htm>


More information about the Dune-devel mailing list