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

[onert] Simplify code using SFINAE technique #14715

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ragmani
Copy link
Contributor

@ragmani ragmani commented Feb 19, 2025

This commit simplify code using the SFINAE technique.

ONE-DCO-1.0-Signed-off-by: ragmani [email protected]

@ragmani ragmani added the PR/ready for review It is ready to review. Please review it. label Feb 19, 2025
@ragmani ragmani requested review from a team and removed request for a team February 19, 2025 07:52
@ragmani ragmani added PR/NO MERGE Please don't merge. I'm still working on this :) and removed PR/ready for review It is ready to review. Please review it. labels Feb 19, 2025
This commit simplify code using the SFINAE technique.

ONE-DCO-1.0-Signed-off-by: ragmani <[email protected]>
@ragmani ragmani force-pushed the onert/simplify_sfinae branch from 2de16fe to 95600ac Compare February 19, 2025 09:16
typename = std::enable_if_t<std::is_base_of<Operation, OperationType>::value>>
std::enable_if_t<std::is_base_of_v<Operation, OperationType>, bool> = true>
Copy link
Contributor Author

@ragmani ragmani Feb 19, 2025

Choose a reason for hiding this comment

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

According to cppreference,

A common mistake is to declare two function templates that differ only in their default template arguments. This does not work because the declarations are treated as redeclarations of the same function template (default template arguments are not accounted for in function template equivalence).

it's better to use the explicit dummy parameter version (as in the "RIGHT" example). This ensures that the function signatures are distinct and avoids redefinition errors.

typename = std::enable_if_t<std::is_base_of<ILoweredGraph, LoweredGraphType>::value>>
std::enable_if_t<std::is_base_of_v<ILoweredGraph, LoweredGraphType>, bool> = true>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto

Comment on lines -38 to +39
template <typename T, typename U>
typename std::enable_if<std::is_integral<T>::value && std::is_integral<U>::value,
typename std::common_type<T, U>::type>::type
ceil_div(T dividend, U divisor)
template <typename T, typename U,
std::enable_if_t<std::is_integral_v<T> && std::is_integral_v<U>, bool> = true>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto

@ragmani ragmani added PR/ready for review It is ready to review. Please review it. and removed PR/NO MERGE Please don't merge. I'm still working on this :) labels Feb 19, 2025
@ragmani ragmani requested a review from a team February 19, 2025 09:20
batcheu
batcheu previously approved these changes Feb 19, 2025
Copy link
Contributor

@batcheu batcheu left a comment

Choose a reason for hiding this comment

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

LGTM

{
assert(dividend > 0 && divisor > 0 && "this implementations is for positive numbers only");
assert(dividend > 0 && divisor > 0 && "this implementation is for positive numbers only");
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor)
Is it fine to include a fix that's not related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it's fine to me :) If you would like to separate it, I will do.

seockho-kim
seockho-kim previously approved these changes Feb 20, 2025
Copy link
Contributor

@seockho-kim seockho-kim left a comment

Choose a reason for hiding this comment

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

LGTM

@ragmani ragmani dismissed stale reviews from seockho-kim and batcheu via e75cff6 February 20, 2025 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR/ready for review It is ready to review. Please review it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants