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>
Support containers without reserve() as result container, for example
std::set/deque/list
Change-Id: Ia96b834c67d5ee74bfb9de2cf6b86639f6b3d5d7
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
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>
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>
Move variadic template arguments to the end for all users in algorithm.h.
Change-Id: I7c8f1254e7de6ee9737e73d1a4721e71c188438e
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Support std::vector and similar classes as input and output.
Change-Id: I1d202d54c18e868ce0e71e4c2b6288565710baa8
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
* 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>
Add function that casts QObjects of a given container to a desired type
and return the result via the same container with the desired value
type.
Change-Id: I45949c982c8dbdd0cce069d62cd2db5c8517f9f5
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Many STL algorithms have value version. So you can only use a predicate:
std::stable_partition(std::begin(list), std::end(list), [](int entry) {
return entry < 20;
});
With this predicates you can write it in a shorter form:
std::stable_partition(std::begin(list), std::end(list), lessThan(20));
The find helpers are moved to predicates too.
Change-Id: I791b3105ca84ef7c5a519d22589a91b5548cf3e4
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Pass the mapping from custom enum to text style in form of a function,
which then can use a switch which is checked by compilers, and
avoids the need to lookup a different enum somewhere else to find
out what the mapping actually is.
That mapping is cached to keep performance as before.
Also, most highlighters created an enum just for the purpose of mapping
to text styles, basically creating duplicated subsets of text style like
enums everywhere. Instead provide a default, identity mapping from text
styles to text styles.
Change-Id: I2ea1ca702b99e36b8742dfda510b1b2753f0a1c2
Reviewed-by: David Schulz <david.schulz@qt.io>
It is seen as good practice to use Container::reserve if you know the size
in advance.
Change-Id: If1398eaa099f4d3f657778aca46516f9bdec14c9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Avoids some code duplication. Available with C++14 / GCC>=4.9.
Change-Id: Iae90466ec9620ffc84b7a45a55490f5fbc8c5b74
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Available now after switching to C++14 and GCC>=4.9
Change-Id: I44e9859a6abe66db16d77b228466b65eadced8ae
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This reverts commit defb18aef4.
This reverts commit 602f8e72be.
The refactoring of transform does not compile with
MSVC2015 Update 2. Retry when we can upgrade to update 3.
Change-Id: I8bfd6ad12c71759af4840c2615d9a8f2390fd4bc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This reverts commit 52f1fe7033.
Revert the revert, which was done because we still support
compilation of 4.1 with GCC 4.7, and that crashes with this patch.
For master/4.2 we require GCC 4.8.
Change-Id: Ifd0b8b4641fe3dd658f9bde62b9e4f888d998ee7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This methods returns a new container with only the unique elements
in the input container. Uses == for comparison of elements.
Change-Id: I80c2027b4d275d27343bd64851c17d42bc971e82
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
These take a container and a predicate and return a Partition
struct with the hit and miss fields. Any element in the original
container will end up in either hit or miss, depending on whether
the predicate returned true for the element or not.
Change-Id: Ia02cd704d6fe1388dc677308440acc48f7c9c1e1
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Do not require containers to provide a size() method. This
makes for a less optimized insertion into the target container,
but most Qt classes should still handle this ok.
The upside is that e.g. the treemodel iterators can now be
transformed.
Change-Id: I4f149720631d9efb7b787332f039074b4c796965
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Currently e.g. this won't compile:
Utils::equal(&Class::toString, QLatin1String("xxx"));
because eqaul_to<QLatin1String> doesn't know how to compare
QString and QLatin1String.
In C++14, equal_to<> (without any template parameter) was added,
which simply works in that case.
Change-Id: I463d01e23f9f0379fea95ef1de4305751af8f1a7
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Use a helper class so that the actual implementation is shared and
introduce a helper class for treating QStringList and other qt
containers in the same way.
There are now 2² overloads, because:
- member function pointer vs everything else
- same container type, different container types
Change-Id: I343ca7d4e0007f7146b2e646c436c22174e27779
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>