use C++ modern features
Open, Needs TriagePublic

Description

use C++ modern features like std::optional? Yes, we can assume C++17 in KF6, let's follow what Qt6 does.

about guidelines using new features : have a look at QtCreator source example that has been using modern C++ for a while, and has gathered rationales around those features

knauss created this task.Sep 9 2019, 9:03 PM
vkrause moved this task from Backlog to Needs Input on the KF6 board.Sep 12 2019, 9:19 AM
meven added a subscriber: meven.Nov 6 2019, 3:23 PM

We can use clang-tidy and its fixits to modernize code.

andisa added a subscriber: andisa.Nov 22 2019, 9:27 PM

I think that we could also do this:

  • Remove magic constants.
  • Break huge functions in smaller ones with meaningful names.
  • Take into consideration the compiler warnings and solve them as much as possible.
  • Take the opportunity to improve the libraries' documentation.
ervin moved this task from Needs Input to In Discussion on the KF6 board.Mar 27 2021, 2:38 PM

(notes from KF6 sprint discussion)

Collected Experiences

std::variant -> poor for performance, not super nice api

std::optional -> used a lot in many places, but not in super-efficient places

std::function has compiler dependent implementation details, but nice to pass callbacks

there is a C++20 specific StringView that is not ABI compatible, do not use it in public API: https://doc.qt.io/qt-6/qutf8stringview.html

enum classes: Qt is not using them in public API

Guideline Ideas

--> at the end, this needs to go to the Library Policy

use std::optional instead of out parameters

QUrl & QString vs. std file system?

add overloads? --> compare to Qt's API approach

smart pointer handling --> should be compared to Qt usage

for non-QObjects, prefer smart pointers

enum classes yes/no?

support for structured bindings

use std::unique_ptr for d-pointers

Other Ideas:

we want to have std::expected but not want to wait for C++XX

try to get it into Qt

else, KCoreAddons

std::function has compiler dependent implementation details, but nice to pass callbacks

But it's rather heavy, how do we feel of templates for passing callbacks?

note to self: create actionable subtasks