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] Apply c++17 features #14647

Open
ragmani opened this issue Feb 12, 2025 · 9 comments
Open

[onert] Apply c++17 features #14647

ragmani opened this issue Feb 12, 2025 · 9 comments

Comments

@ragmani
Copy link
Contributor

ragmani commented Feb 12, 2025

What

Let's apply C++17 features to onert. The goal is to modernize the codebase by leveraging new language features, thereby simplifying the code and improving maintainability.

Why

  • Simplification: Modern C++17 features can reduce boilerplate code and improve code readability.
  • Maintainability: Using updated syntax and constructs makes it easier to maintain and extend the code in the future.
  • Performance & Safety: Some C++17 features can lead to better performance and more robust error handling.
  • Consistency: Standardizing the codebase to a modern C++ standard promotes consistency across the project.

Features to be applied

  • Nested Namespace Declarations

    • Simplifies deeply nested namespace syntax, reducing verbosity and improving readability.
    • cppreference
  • Inline Variables

    • Avoids multiple definition issues by allowing variables to be defined in headers without violating ODR.
    • cppreference
  • Structured Bindings

    • Provides a concise way to unpack tuples or struct members, making code cleaner and easier to understand.
    • cppreference
  • if constexpr

    • Enables compile-time conditional branching in templates, reducing code complexity and avoiding unnecessary instantiations.
    • cppreference
  • Fold Expressions

    • Simplifies the handling of variadic templates by reducing parameter packs with a single expression.
    • cppreference
  • Template Argument Deduction for Class Templates (Deduction Guides)

    • Eliminates the need to specify template arguments explicitly when constructing objects, enhancing code brevity.
    • cppreference
  • Filesystem Library (std::filesystem)

    • Standardizes file and directory operations, making code more portable and easier to maintain compared to platform-specific APIs.
    • cppreference
  • std::optional

    • Offers a safer alternative to pointers or sentinel values for representing optional data, improving code clarity and robustness.
    • cppreference
  • std::variant

    • Provides a type-safe union for handling multiple types in a single variable, enhancing code safety and flexibility.
    • cppreference
  • std::any

    • Enables storage of any type in a type-safe manner, useful for heterogeneous collections without compromising type safety.
    • cppreference
  • std::string_view

    • Allows efficient non-owning views over strings, reducing unnecessary copying and improving performance when handling substrings.
    • cppreference
  • Parallel Algorithms (Execution Policies)

    • Facilitates the parallelization of standard algorithms, potentially improving performance on multi-core systems with minimal code changes.
    • cppreference
  • [[nodiscard]] Attribute

    • Helps prevent bugs by issuing warnings when important return values are ignored, ensuring that critical results are handled properly.
    • cppreference
@ragmani
Copy link
Contributor Author

ragmani commented Feb 13, 2025

@ragmani
Copy link
Contributor Author

ragmani commented Feb 13, 2025

if constexpr

@ragmani
Copy link
Contributor Author

ragmani commented Feb 14, 2025

@ragmani
Copy link
Contributor Author

ragmani commented Feb 14, 2025

Template Argument Deduction for Class Templates (Deduction Guides)

This feature could negatively impact readability, so I will not be applying it.

@ragmani
Copy link
Contributor Author

ragmani commented Feb 14, 2025

Filesystem Library (std::filesystem)

This feature was already resolved by #12450

@ragmani
Copy link
Contributor Author

ragmani commented Feb 14, 2025

std::optional

Considering consistency with the existing code and potential performance overhead, I did not find any suitable places to apply std::optional.

@ragmani
Copy link
Contributor Author

ragmani commented Feb 14, 2025

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

No branches or pull requests

1 participant