Skip to content

Conversation

phcerdan
Copy link
Contributor

@phcerdan phcerdan commented Dec 14, 2023

Also removes dead code related to METADATAPRINT

Fix #1454

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • [NA] Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5

@phcerdan phcerdan requested a review from blowekamp December 14, 2023 00:37
@github-actions github-actions bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module labels Dec 14, 2023
@phcerdan phcerdan force-pushed the fix_metadataobject_print branch from e7bce87 to c1b352c Compare December 14, 2023 00:46
@phcerdan phcerdan added the action:ApplyClangFormat Add this label to a pull request to apply `clang-format` to the branch label Dec 14, 2023
Also removes dead code related to METADATAPRINT

Fix InsightSoftwareConsortium#1454
@phcerdan phcerdan force-pushed the fix_metadataobject_print branch from c1b352c to 1afdbce Compare December 14, 2023 00:50
{
template <typename TIterable>
void
printIterable(std::ostream & os, const TIterable & iterable)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting pull request, thanks @phcerdan

Can you possibly hide printIterable (or whatever its name will be) from the public API? Because it isn't intended to be exposed directly to the end user, right? I guess it should be possible to make it a private (preferably static) member function of MetaDataObject. Otherwise, it might be possible to define it as a lambda, hidden locally inside MetaDataObject::PrintValue, but that seems more challenging to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you can make it private, you might as well just name the function something like PrintHelper, rather than printIterable. My 2 cent!

Comment on lines +34 to +40
template <typename T, typename = void>
inline constexpr bool is_iterable_print_v = false;
// Specialize for std::vector<T> and std::vector<std::vector<T>>
template <typename T>
inline constexpr bool is_iterable_print_v<std::vector<T>, std::void_t<>> = true;
template <typename T>
inline constexpr bool is_iterable_print_v<std::vector<std::vector<T>>, std::void_t<>> = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to see a use case for variable templates, thanks @phcerdan. Unfortunately "itkMetaDataObject.hxx" is usually #include'd (indirectly) by end users, and I guess it's not the intention to add is_iterable_print_v to the global namespace of the user, right? If you agree, you may possibly make is_iterable_print_v a private static member of MetaDataObject. Or otherwise, maybe it's simpler to just add overloaded private static MetaDataObject::IsIterablePrint(const T&) member functions. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points @N-Dekker, I will make static private members

Copy link
Contributor Author

@phcerdan phcerdan Dec 14, 2023

Choose a reason for hiding this comment

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

GCC doesn't like it... (moving is_iterable_print inside the class).
https://stackoverflow.com/questions/72190700/explicit-template-argument-list-not-allowed-with-g-but-compiles-with-clang

I will explore further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems fixed in gcc14, but we cannot afford that.

Copy link
Contributor

@N-Dekker N-Dekker Dec 14, 2023

Choose a reason for hiding this comment

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

Another option I guess would be to have constexpr static member functions IsIterablePrint(const T&) overloaded (rather than "specialized") for std::vector<T> and std::vector<std::vector<T>>, right?

You could then use it like:

if constexpr (IsIterablePrint(iterable))

I guess 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the name of the boolean, maybe something like ShouldBePrintedElementWise ?

@thewtex thewtex requested a review from hjmjohnson December 14, 2023 21:46
Copy link
Member

@hjmjohnson hjmjohnson left a comment

Choose a reason for hiding this comment

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

I am very supportive of these efforts! Modern C++ can accomplish the desired task much more cleanly and robustly.

I appreciate @N-Dekker comments to fortify the API (avoid leaky API) and would like to see those comments addressed before finalizing this PR.

@dzenanz
Copy link
Member

dzenanz commented Sep 3, 2024

Should this be closed, given that #4814 was merged?

@phcerdan
Copy link
Contributor Author

This PR had two features:
Fix printing of values in MetaDataObject. Fixed in #4814
Allow printing of std::vector<std::vector> and other iterables. This part is being tackled in #4831.

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

Labels

action:ApplyClangFormat Add this label to a pull request to apply `clang-format` to the branch area:Core Issues affecting the Core module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MetaDataDictionary::Print only prints [UNKNOWN_PRINT_CHARACTERISTICS]

5 participants