Skip to content

ARROW-6515: [C++] Clean type_traits.h definitions#5885

Closed
fsaintjacques wants to merge 4 commits intoapache:masterfrom
fsaintjacques:ARROW-6515-clean-type-traits
Closed

ARROW-6515: [C++] Clean type_traits.h definitions#5885
fsaintjacques wants to merge 4 commits intoapache:masterfrom
fsaintjacques:ARROW-6515-clean-type-traits

Conversation

@fsaintjacques
Copy link
Contributor

@fsaintjacques fsaintjacques commented Nov 22, 2019

The goal of this PR is to uniformize the usage of type traits and pattern matching on static type information.

  • Introduce arrow::enable_if_t since we're still on C++11. This removes a small amount of boilerplate, e.g. typename (expr)::type. Refactor most code to use this, except where type_traits was not included.
  • Major overhaul of type_traits.h by exporting a uniformized (as much as I could) aliases, i.e. is_X_type and the accompanying enable_if_X.
  • Removed old struct type traits, e.g. IsSigned....
  • Removed catch-all-visitor method and replaced them with explicits missing visitor. This will help the implementation of new types to error missing implementation at compile time instead of runtime.
  • Uniformize usage of enable_if with methods, by using the return-place form instead of parameter-place (except when in the constructor).
  • Fixed some missing implementation when trivial.
  • Added c_type to BooleanType

@github-actions
Copy link

The goal of this PR is to uniformize the usage of type traits and
pattern matching on static type information.

- Introduce `arrow::enable_if_t` since we're still on C++11. This
  removes a small amount of boilerplate, e.g. `typename (expr)::type`.
  Refactor most code to use this, except where type_traits was not
  included.
- Major overhaul of `type_traits.h` by exporting a uniformized (as much
  as I could) aliases, i.e. `is_X_type` and the accompanying
  `enable_if_X`.
- Removed old struct type traits, e.g. `IsSigned...`.
- Removed catch-all-visitor method and replaced them with explicits
  missing visitor. This will help the implementation of new types to
  error missing implementation at compile time instead of runtime.
- Uniformize usage of `enable_if` with methods, by using the
  return-place form instead of parameter-place (except when in the
  constructor).
- Fixed some missing implementation when trivial.
@fsaintjacques fsaintjacques force-pushed the ARROW-6515-clean-type-traits branch from cdaa360 to beea0cc Compare November 22, 2019 15:18
Copy link
Member

@bkietz bkietz left a comment

Choose a reason for hiding this comment

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

This looks like a great clean up, thanks for doing this

template <typename Enable = Status>
auto VisitValue(const Scalar& value) ->
typename std::enable_if<!with_error_status, Enable>::type {
auto VisitValue(const Scalar& value) -> enable_if_t<!with_error_status, Enable> {
Copy link
Member

Choose a reason for hiding this comment

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

The signature is poorly formed: The enabling condition does not depend on a deduced template parameter so SFINAE can't happen. It's probably not disabling what it was intended to disable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you check the new version?

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Good idea!

Copy link
Member

@wesm wesm left a comment

Choose a reason for hiding this comment

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

Definitely a welcome cleanup, thanks for working through this


template <typename T>
using is_number_type = std::is_base_of<NumberType, T>;
// only in C++14
Copy link
Member

Choose a reason for hiding this comment

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

Is there a conflict when compiling with -std=c++14?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There shouldn't because it's in arrow namespace.

This class attribute is used rarely, no point in keeping it for now. I
would suggest to add it to `TypeTraits` classes if needed again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants