File indexing completed on 2024-04-28 16:53:07
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Ivan Cukic <ivan.cukic(at)kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef ASYNQT_BASE_FILTER_H 0008 #define ASYNQT_BASE_FILTER_H 0009 0010 #include <QFuture> 0011 #include <QFutureWatcher> 0012 0013 #include <memory> 0014 #include <type_traits> 0015 0016 #include "../private/operations/filter_p.h" 0017 0018 namespace AsynQt 0019 { 0020 /** 0021 * Takes a future of a future, and flattens it out. 0022 * 0023 * If any of the futures is canceled, the resulting future 0024 * will be canceled as well. 0025 * 0026 * @arg future future that contains another future of type T 0027 * @returns a single-level future of type T 0028 */ 0029 template<typename _Result, typename _Predicate> 0030 QFuture<_Result> filter(const QFuture<_Result> &future, _Predicate &&predicate) 0031 { 0032 return detail::filter_impl(future, std::forward<_Predicate>(predicate)); 0033 } 0034 0035 namespace operators 0036 { 0037 template<typename _Predicate> 0038 inline detail::operators::FilterModifier<_Predicate> filter(_Predicate &&predicate) 0039 { 0040 return detail::operators::FilterModifier<_Predicate>(std::forward<_Predicate>(predicate)); 0041 } 0042 0043 } // namespace operators 0044 0045 } // namespace AsynQt 0046 0047 #endif // ASYNQT_BASE_FILTER_H