29 Commits

Author SHA1 Message Date
Miłosz Kosobucki
362100d07a Fortify uses of std::min/max against Windows
In public headers it's better to add parentheses around std::min/max
because on Windows, these can be treated as the (in)famous min/max
macros from Windows SDK (minwindef.h) if the user doesn't define
NOMINMAX.
2024-10-29 19:42:35 +01:00
Allen Winter
52611ec317 Standardize project to KDAB copyright policy
For individual files: use year of file creation
For entire project:
  remove year from the statement
  use the © where feasible

reference:
https://matija.suklje.name/how-and-why-to-properly-write-copyright-statements-in-your-code
2024-01-19 15:51:29 -05:00
Daniel Nicoletti
556d67cff4 Add nightly CI 2023-12-04 13:54:57 -03:00
Daniel Nicoletti
d3f853d390 CI: Fix build issues and use master branch 2023-11-30 12:47:49 -03:00
Allen Winter
0d9f524da7 markdown clean all the README.md's
Change-Id: Id3fa86c7026c2aa852abcb2e36779328e875d588
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/132635
Reviewed-by: Allen Winter <allen@kdab.com>
2023-10-22 18:12:28 +02:00
Allen Winter
c2f948d3d5 reuse headers
Change-Id: I2d7bd3dc68dc99a89a9d0a1ad5fe50257dc2773d
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/132633
Reviewed-by: Allen Winter <allen@kdab.com>
2023-10-22 17:10:22 +02:00
Daniel Nicoletti
6b26c888b3 Remove qmake files
Change-Id: Ia1206a4876f141c9bb8d73e63aa2444d83d81607
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/132432
Reviewed-by: Allen Winter <allen@kdab.com>
2023-10-20 21:32:29 +02:00
Allen Winter
5c9e4a76c7 various - split the author from the copyright line
Move the author from the copyright line to its own line.

Change-Id: I10cf4be74feede4654e29fe137605592a77d5baf
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/132617
Reviewed-by: Allen Winter <allen@kdab.com>
2023-10-20 21:23:47 +02:00
Allen Winter
1b343d51e6 Run cmake-lint and cmake-format on the project
Change-Id: I700641db57ed4be043099a4dbead6abd33af1629
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/132427
Reviewed-by: Allen Winter <allen@kdab.com>
2023-10-18 13:43:20 +02:00
Daniel Nicoletti
17f667bbcb Port to CMake
Change-Id: If90ba0a711e2bd8201d32a5d2fbfa3a3954a7a4b
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/132391
Reviewed-by: Allen Winter <allen@kdab.com>
2023-10-18 13:20:02 +02:00
Giuseppe D'Angelo
6f55d1cd1b Fix kdToContainer compilation
kdToContainer offers a convenience operator|, basically
mimicking range-v3 / C++23's ranges::to:

  vector | kdToContainer<QList>()

The operator| is defined as a hidden friend of a helper class template.
We can't however declare it "directly" inside the class template,
because it's a class template: different instantiations would redeclare
the same function. Instead, isolate it in a non-template base class.

Change-Id: I581da19cb2571b7455a1844f59c08c1fb69ca17b
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/123540
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Allen Winter <allen@kdab.com>
2023-03-22 01:32:55 +01:00
Giuseppe D'Angelo
78ea947edc Long Live propagate_const
A reimplementation of propagate_const from the Library Fundamentals TS.

Qt-based applications tend to use quite a lot of (raw) pointers as
class data members. This is just... habits, I guess; Qt encourages
this particular style. For instance

  class SomeWidget : public QWidget {
      QLineEdit *m_lineEdit;
      QComboBox *m_comboBox;
      ...
  };

But why pointers, rather than non-pointers? That is, why not doing

  class SomeWidget : public QWidget {
      QLineEdit m_lineEdit;
      QComboBox m_comboBox;
      ...
  };
?

A reason is lower the #include dependencies for SomeWidget.h (can just
forward declare), so better compile times. Another is that ownership of
QObjects is non-obvious; some of the objects may be owned by something
else, so we shouldn't destroy them directly when we destroy *this.

(Another one, that doesn't apply very often, is that some of the members
may be only optionally set.)

There is at least one _design_ difference between the pointers vs
non-pointers scenario: const correctness. If your SomeWidget has a
method

  void update() const;

then you cannot modify the data members (if they're not pointers), but
you can happily do

  void SomeWidget::update() const {
      m_lineEdit->setText("hello");
  }

which violates const correctness. This could be deliberate (but that
sounds silly); more likely, this will happen by accident -- you're in
a const method, and you end up doing something which mutates the
observable state of *this by manipulating a pointee.

Why does the above compile? What's const in there is the pointer itself,
not the object it points to; and pointers do not deep propagate
constness (they're "shallow const").

This is a almost universally bad situation
.
===

Linters aside, how can we prevent this sort of mistakes?

Enter propagate_const, a drop-in replacement for raw pointers as well as
smart pointers (which also suffer from the same issue), that deeply
propagates const:

  class SomeWidget : public QWidget {
      propagate_const<QLineEdit *> m_lineEdit;
      propagate_const<QComboBox *> m_comboBox;
      ...
  };

With this in place, we get back const correctness:

  void SomeWidget::update() const {
      // ERROR: m_lineEdit-> will yield a `const QLineEdit *`
      m_lineEdit->setText("hello");
  }

propagate_const has been proposed for the C++ Extensions for Library
Fundamentals version 3. Unfortunately

1) MSVC does not implement it,
2) both GCC and Clang have bugs in their implementations that make
them unsuitable for Qt development.

So here's a new reimplementation that works around those bugs.

Change-Id: Ief2051ba8f2ed8aa241359a2e75ecc9440ba2a60
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/117692
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2023-01-17 16:31:46 +01:00
Allen Winter
48805d34a5 clang-format the entire project
Change-Id: I7bd6fcae97212dbde5b36caa74d74723166db42e
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/120008
Reviewed-by: Allen Winter <allen@kdab.com>
2023-01-02 17:42:55 +01:00
Allen Winter
cf00c616ce various - codespell the entire project
Change-Id: I5ab442648a804cb6f94cfd90bf6bc4c4ab6bbf4b
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/120014
Reviewed-by: Allen Winter <allen@kdab.com>
2023-01-02 17:28:17 +01:00
Allen Winter
aba6f84eb7 various - end-of-file-fixer
Change-Id: I151e0e53c85b29635c30e591650e22124b97127e
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/120007
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Allen Winter <allen@kdab.com>
2023-01-02 17:15:03 +01:00
Allen Winter
2ae3ab5be0 update copyright year
Change-Id: I432f497a7bb21a49e9eed3f9184b048248576160
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/120009
Reviewed-by: Allen Winter <allen@kdab.com>
2023-01-02 17:13:56 +01:00
Allen Winter
a20588b92b update copyright year
Change-Id: If29d03a3b45a888be0b75cdf2405faebbba99b2b
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/106758
Reviewed-by: Allen Winter <allen@kdab.com>
2022-01-21 22:00:34 +01:00
Marc Mutz
7e2aea4012 Add using QObject::QObject to all test classes
Fixes clazy-ctor-missing-parent-argument.

Change-Id: Idb2dbc17fb6bb140087601dd02ef19b65c97b02c
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/100098
Reviewed-by: Sérgio Martins <sergio@kdab.com>
2021-07-15 09:57:48 +02:00
Marc Mutz
fd0982260d future-backports: include README.md as OTHER_FILES
For easier handling with QtCreator.

Change-Id: If26bc276899b241310aed95f777735b575cdb057
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/99624
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
2021-07-04 17:28:18 +02:00
Marc Mutz
30801e4417 Add a configure check for C++20 and compile more tests in more C++ versions
Increases test coverage.

Change-Id: Ie996fea85401175d5fc5a7182fb2a0c35e7739c7
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/98817
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Sérgio Martins <sergio@kdab.com>
2021-06-18 22:59:11 +02:00
Marc Mutz
cc03c86bf1 Fix some Clazy warnings
Change-Id: I97c13c0f1fad72518f8515e2b6ef724f6b91bea5
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/98824
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Sérgio Martins <sergio@kdab.com>
2021-06-17 17:34:34 +02:00
Giuseppe D'Angelo
89b07fa284 Fix typo
Change-Id: Id5bf76a9032e7ac9313b4640c16208b76bfb2e40
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/95448
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2021-04-08 16:12:58 +02:00
Giuseppe D'Angelo
6118acf67d Long live kdToContainer
This is some code I have had in my Qt build for a while now.
Given the barrier to put this into QtCore is too high, maybe
it's useful to publish elsewhere, so here it is.

Change-Id: I519d360920539ee2048536b4e4eeb706fe03d64f
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/94929
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Ivan Čukić <ivan.cukic@kdab.com>
2021-04-08 16:10:33 +02:00
Marc Mutz
bc6b2af84f DuplicateTracker: never allocate less than Prealloc buckets
The unordered_set:reserve() can be expected to do that already. But
for our (numBuckets) constructors, we need to do the check ourselves.

Change-Id: I04e1d56e14abec1f530ecfd181eb20a97445c698
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/88301
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
2021-01-04 14:56:18 +01:00
Marc Mutz
0f5b8de223 Long live DuplicateTracker!
DuplicateTracker transparently wraps std::pmr::unordered_map with a
std::pmr::monotonic_memory_resource in a non-copyable, non-movable
class with a narrowly-focussed API (basically, hasSeen()). If C++17
<memory_resource> isn't available, it falls back to the default
std::allocator.

This is the third iteration of this class. The first was
QDuplicateTracker in Qt, which suffers from too small a static buffer,
and a very restricted API.

The second iteration was developed in a customer project and got the
size of the static buffer (almost) right, as well as adding contains()
and set(). The latter was made possible because, unlike
QDuplicateTracker, this version always used std::unordered_set, just
with different allocators, so the interface and semantics of
decltype(set()) no longer varied wildly between C++17 and C++14
builds.

In this third iteration, I factored the preallocated storage into a
separate base class, to allow more implementation sharing between
DuplicateTracker<T, N>s with same T, but different N. It also adds
template arguments for the Hash and Equal template arguments (which is
important when you don't, yet, use Qt 5.15, because then you might
want to pass KDToolBox::QtHasher). Lastly, it exposes the
unordered_set(N) ctor, so we can control the bucket_count() already at
construction time, which means we no longer waste a default-sized
bucket list allocated from the monotonic_buffer_resource when
default-constructing a DuplicateTracker and then calling reserve().

Change-Id: Iaf7bd1d2291796e05beb36fef7172aed0c3e6c1f
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/88299
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2021-01-04 13:38:24 +01:00
Allen Winter
35cbcbda28 update copyright year
Change-Id: I7e05890e8d9573644ebccbcd05e63d62b51fbd41
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/89461
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Tested-by: Continuous Integration <build@kdab.com>
2021-01-02 21:59:06 +01:00
Allen Winter
b3040c6f2e cpp/future-backports/include/k20/detail/erase_if.h - use https
Change-Id: Ife50fc42c9193e65a6e846932259f9b51d76698e
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/86393
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
2020-10-21 16:26:47 +02:00
Marc Mutz
2e52e8134c k20::erase: also handle deque, list, forward_list, and string
This completes this module.

Change-Id: I0e1240e32589ad2199cfdac0504f79e8adcce885
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/86220
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
2020-10-21 09:42:16 +02:00
Marc Mutz
43650b872f Short live k20::erase/_if()!
This is a back-port of C++20's Uniform Container Erasure, for vector
and the associative containers. It's easy to extend to all the other
container types, too, though, both in the implementation as well as in
the test.

This also lays the framework for more such components in the future
(k20::span?). See the README.md for more details.

Change-Id: I6d3d216c2d14910d09fa7438e97fe3ff6e3fe97a
Reviewed-on: https://codereview.kdab.com/c/kdab/KDToolBox/+/85864
Tested-by: Continuous Integration <build@kdab.com>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
2020-10-12 11:02:01 +02:00