Commit Graph

23 Commits

Author SHA1 Message Date
Tobias Hunger
831b84a6fd Utils: Add take
Add a new algorithmn to take the first match in a container out of the container.

It takes a pointer to something and will try to match against a smart pointer
stored in the container. Besides that it also accepts the usual like a predicate,
member variable or member function.

Change-Id: I4aabd4d43aa076a534da6488d0f9c3695ba79c09
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-03-12 14:14:01 +00:00
Eike Ziller
8944ba0391 Utils::transform: Add support for various map types as result
Add support for output as std::map/unordered_map/set and QMap and QHash,
when giving the full result type as template argument. For std::
(unordered_)map, the function must return a std::pair<Key,Value>, for
QMap and QHash it can also be QPair<Key,Value>.

Change-Id: If3dff17ab6aa5d1b11abc244813fd885d10c75a4
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-12-20 09:58:50 +00:00
Eike Ziller
f62b24c475 Utils::transform: Support containers without reserve()
Support containers without reserve() as result container, for example
std::set/deque/list

Change-Id: Ia96b834c67d5ee74bfb9de2cf6b86639f6b3d5d7
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-12-20 09:58:27 +00:00
Marco Bubke
91e40e12db Utils: Converter to raw pointer and references
Sometimes you want to get raw pointer container from smart pointer
container and reference container from value container.

Change-Id: Ia018d572ac0a7bf742f3937dc38ee30670a3ca73
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-20 09:58:17 +00:00
Eike Ziller
e0a23664aa Utils::transform: Allow usage with non-const source containers
Makes it possible to e.g. transform to list of reference_wrappers.

Change-Id: Ib608034fc3f296824c289edd27563bc7a196ac6d
Reviewed-by: hjk <hjk@qt.io>
2017-12-19 07:35:38 +00:00
Christian Stenger
299d0f0e4f Tests: Fix compile with MSVC2015
Change-Id: Ic9a1839325febeb6bde0b656dce88342f3955c53
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-13 13:44:03 +00:00
Eike Ziller
6b48beeeb0 Support specifying complete result type in Utils::transform
Can come in handy when the function or member does not directly return
the right value type for the result list, but is implicitly convertable
to it. For example from pointer to class to pointer to superclass, or
from int to double.

const auto result
    = Utils::transform<QVector<double>>(v, &ValueType::intMember)

Change-Id: I0e1914d70bb2580b91098dd37e85a31ca14b0ae6
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-12-12 14:44:15 +00:00
Eike Ziller
fb4f7e7420 Simplify transform and add support for more input container types
Change-Id: Ib75cfcc7741be686c0117fbb27df869e14db4f69
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-12-07 09:55:42 +00:00
Tobias Hunger
2c09424c13 Utils: Clean up Utils::findOr and Utils::findOrDefault
Change-Id: I638e68480d3985b6df9a18aa96a067ee68484b12
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 14:41:15 +00:00
Tobias Hunger
b81d788793 Utils: Support more containers with Utils::transform
Support std::vector and similar classes as input and output.

Change-Id: I1d202d54c18e868ce0e71e4c2b6288565710baa8
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 14:11:28 +00:00
Tobias Hunger
33fc20ab51 Utils: Improve Utils::contains
* Consistently use anyOf to implement contains.
* Support contains over an container of std::unique_ptr matching a pointer.

Change-Id: I0180f3ec3d5935d8afeeac67a745d4b38a01674d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 13:16:43 +00:00
Tobias Hunger
9b832f670d Utils: Implement more Utils::anyOf variations
Change-Id: I0cba5b58dde6003f5c5cb399142f985cbe83f0a7
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-12-01 13:16:37 +00:00
Christian Stenger
e5fae9b914 Tests: Fix compile on Windows and Linux
Template code inside utils/algorithm.h is not correctly instantiated when
respective containers that shall use these functions are included after
the algorithm file.
Additionally there had been issues using nullptr as comparison inside
QCOMPARE().

Change-Id: I2bd6baf3890090c5f5bbbd6229afb9aeeb7617ef
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-30 09:21:51 +00:00
Eike Ziller
c1aa745813 Add missing include to algorithm test
Change-Id: Ia7302723a0ec41456ca99704b7f8c680f6893c5d
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 12:09:49 +00:00
Eike Ziller
c90e5b50dc Algorithm: Support std::vector<std::unique_ptr> with contains and findOr
Change-Id: I01cb71c06b405f071498ed8752f9acac44d2b223
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-11-29 08:59:52 +00:00
Christian Stenger
eaf4b67461 Tests: Fix compile on Linux and Windows
Change-Id: Ie8db68769a2419c9ad8700d9eef1d4093c209d9b
Reviewed-by: hjk <hjk@qt.io>
2017-11-28 08:47:39 +00:00
Tobias Hunger
566b118a87 Utils: Make algorithms take more containers
Change-Id: I05bd1052bbc2c6481fdec8a3763d9ae4f3dc8f44
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-11-27 15:00:16 +00:00
Orgad Shaneh
4136e36c6f Algorithm: Add a member variant for transform
Change-Id: I329ee764cc13dd8b794c6769a2baf2f41d6a9983
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-03-10 11:37:03 +00:00
Orgad Shaneh
98a0c816f7 Tests: Do not use deprecated Qt algorithms
Change-Id: I3ca177b69df3540729a98d8d3b6287df36a47ea0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-08-15 07:22:59 +00:00
Eike Ziller
c3ee2d06ba Algorithm: Allow sorting container of pointers with member (function)
Change-Id: I2928081750f86b66e969ec2f7ade9e67ce19a825
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2016-08-09 13:17:43 +00:00
Orgad Shaneh
a23e0692b4 Utils: Introduce sort variants for member and member function
Change-Id: Iff29f2c55a08e85de7f0ff4e431f326e351e5305
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-08-09 10:51:28 +00:00
Christian Stenger
d8c18de93c Tests: Fix compile with Qt5.5/MSVC 2013
Change-Id: I60b7222380486c965701abf6fcbfad460797ab27
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-07-22 12:06:58 +00:00
Eike Ziller
61ab1382dc Add auto test for algorithms
The currently most interesting is Utils::transform.

Change-Id: Ic21ec098f15ae4564227a84d11ef95f57ac72d6c
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2016-07-11 09:56:18 +00:00