Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compile in itk reader/writer #1153

Closed
wants to merge 26 commits into from

Conversation

kerautret
Copy link
Member

PR Description

fix compile in itk reader/writer

Checklist

  • [n.a] Unit-test of your feature with Catch.
  • [n.a] Doxygen documentation of the code completed (classes, methods, types, members...)
  • [n.a] Documentation module page added or updated.
  • New entry in the ChangeLog.md added.
  • No warning raised in Debug cmake mode (otherwise, Travis C.I. will fail).
  • All continuous integration tests pass (Travis & appveyor)

@@ -64,7 +64,8 @@ namespace DGtal {
const Domain& domain = dgtal_itk_image.domain();

typedef ConstImageAdapter<DGtalITKImage, Domain, functors::Identity, Value, Functor> AdaptedImage;
const AdaptedImage adapted(dgtal_itk_image, domain, functors::Identity(), aFunctor);
const functors::Identity identityFunctor{};
Copy link
Member

Choose a reason for hiding this comment

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

why {}?

Copy link
Member Author

Choose a reason for hiding this comment

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

I apply the same change of @rolanddenis ;) looks fine without with my compilo but I suppose that there a reason.

Copy link
Member

Choose a reason for hiding this comment

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

😄
In that case, it is exactly the same as without {}: it calls the constructor without argument. It is a new syntax from C++11. It enhances the construction of object and, especially, it allows me to replace a common mistake that I make:
const functors::Identity identityFunctor();
by a valid syntax:
const functors::Identity identityFunctor{};
:octocat:

Copy link
Member

Choose a reason for hiding this comment

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

Well, I would have preferred to get the () removed instead of something that can be ambiguous for non-c11 dev.
(Not sure to see why this new syntax enhance the construction.. I'll have to read the doc;))

@dcoeurjo
Copy link
Member

beside my minor comment, this PR is fine.
Thanks

@dcoeurjo dcoeurjo self-assigned this Mar 28, 2016
@kerautret
Copy link
Member Author

ok @dcoeurjo I have remove the {} since @rolanddenis confirms that in this case it is equivalent.
Perhaps we can merge and change other {} in other PR? (there also some in DGTalTools)

@dcoeurjo
Copy link
Member

Yes I agree. Thanks

@dcoeurjo
Copy link
Member

(Just waiting for Travis ;))

@rolanddenis
Copy link
Member

Don't merge yet: do you have try to compile it with clang ? It should fail because of the missing {}.
I can't try this specific file (my ITK is not compiled with C++11) but this simple example:

#include "DGtal/base/BasicFunctors.h"
int main()
{
  const DGtal::functors::Identity id;
  return 0;
}

failed with clang++ and it is not a bug.
(explanation coming)

@rolanddenis
Copy link
Member

There is a small rule when using default initialization with constant object (§8.5/7):

If a program calls for the default initialization of an object of a const-qualified type T, T shall be a class type with a user-provided default constructor.

It seems that this rule exists to avoid invalid initialization of POD class with const qualifier.
In order to compile, there is many solutions:

  • declaring a user-provided default constructor. "user-provided" means that the constructor is not set to the default (with = default at the end of the first declaration). Therefore, the class becomes non-POD.
  • removing the const qualifier (against the const correctness).
  • explicitly using the "value initialization" (instead of the "default initialization") by adding {}:
    const DGtal::functors::Identity id{};
    or, before C++11:
    const DGtal::functors::Identity id = DGtal::functors::Identity();

gccdoes not complain because it implements a proposed change in the draft, coming after the C++11standard that weaken this rule for class without members (see http://stackoverflow.com/questions/26077807/why-does-gcc-allow-a-const-object-without-a-user-declared-default-constructor-bu and http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#253 ). This change seems to be still not applied in the last draft.

Refs:

@kerautret
Copy link
Member Author

thanks @rolanddenis , yes you are right it fails, perhaps I wrongly switch branch by testing by removing it, sorry ;( !
So I revert to the initial good version ;)

@dcoeurjo
Copy link
Member

Thanks for the details! I've learned a lot of things.
So what should we do? Should we recommend to add default constructors to our functors or let the user deal with the {} (or its pre-c++11 version) ?

@kerautret
Copy link
Member Author

perhaps the default constructor is better but we will lost the POD of Identity, but I don't know if it is a problem to be no more Plain Old Data ?

@rolanddenis
Copy link
Member

I found that strange to provide a default constructor that do nothing in a class that owns nothing (and that could have only static methods). If using {} is really a problem, I prefer removing the const. A maybe better solution is to mix the old fashion way with auto:
const auto id = DGtal::functors::Identity();
?

@kerautret
Copy link
Member Author

Perhaps the {} is fine from the user point of view, since the message of Clang is really explicit:
capture d ecran 2016-03-31 a 22 58 12
and also the auto should be fine..

@dcoeurjo
Copy link
Member

dcoeurjo commented Apr 1, 2016

Ok, you're both right. Let's keep the {} for const instanciations.
Thanks for the discussion 😄

So, can i merge this branch or you need to revert your edits, Bertrand ?

@kerautret
Copy link
Member Author

I revert it just now, I was waiting the end of discussion ;)

@dcoeurjo
Copy link
Member

dcoeurjo commented Apr 1, 2016

🆗

@kerautret
Copy link
Member Author

done

dcoeurjo and others added 5 commits April 3, 2016 18:53
* fix empty faces in align axis tubular direction and better optimisation on face association (approx hausdorff distance instead using direction)

* add visual test

* complete testMesh

* Changelog

* fix typo test and better test nb faces

* clean in test

* typo
@kerautret
Copy link
Member Author

@dcoeurjo can we merge?

@dcoeurjo
Copy link
Member

dcoeurjo commented Apr 5, 2016

Yep merging. Thanks

@kerautret
Copy link
Member Author

thanks! ;)

Le 5 avr. 2016 à 10:53, David Coeurjolly notifications@github.com a écrit :

Yep merging. Thanks


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

@dcoeurjo
Copy link
Member

dcoeurjo commented Apr 5, 2016

ok.. there is an issue.. could you please merge the master back ?

@kerautret kerautret closed this Apr 5, 2016
@kerautret
Copy link
Member Author

it looks like it was just a meriging bug ! ;)

Le 5 avr. 2016 à 12:35, David Coeurjolly notifications@github.com a écrit :

ok.. there is an issue.. could you please merge the master back ?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

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

Successfully merging this pull request may close these issues.

None yet

4 participants