Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Lazy tentative to replace of auto_ptr with unique_ptr and move to c++14 #197

Merged
merged 2 commits into from
Nov 5, 2019

Conversation

sloriot
Copy link
Contributor

@sloriot sloriot commented Nov 5, 2019

I'm not claiming this is perfect, but at least it compiles and the testsuite (simply running ctest) works.

also add some std::move to please the compiler
remove the c++98 flag in the main cmake script

Testsuite (at least simply running ctest) works
@vmora vmora merged commit b56096b into Oslandia:master Nov 5, 2019
@vmora
Copy link
Contributor

vmora commented Nov 5, 2019

"au temps pour moi" and thanks a lot @sloriot

@mhugo
Copy link
Contributor

mhugo commented Nov 6, 2019

@sloriot Thanks !

@mhugo mhugo mentioned this pull request Nov 6, 2019
PreparedGeometry::PreparedGeometry( std::auto_ptr<Geometry> geometry, srid_t srid ) :
_geometry( geometry ),
PreparedGeometry::PreparedGeometry( std::unique_ptr<Geometry>&& geometry, srid_t srid ) :
_geometry( geometry.release() ),
Copy link

@lrineau lrineau Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a function claims ownership of a pointer, the unique_ptr is best taken by value:

PreparedGeometry::PreparedGeometry( std::unique_ptr<Geometry> geometry, srid_t srid ) 
    _geometry( std::move(geometry) ),

For a long explanation, you can read https://stackoverflow.com/a/8114913/1728537.

The semantic of void f(std::unique_ptr<Geometry>&& geometry) is that f may take the ownership.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, passing rvalue references of unique_ptr seems very confusing to me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants