/**************************************************************************** ** ** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz ** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or (at your option) the GNU General ** Public license version 3 or any later version approved by the KDE Free ** Qt Foundation. The licenses are as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-2.0.html and ** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #if 0 #pragma qt_sync_skip_header_check #pragma qt_sync_stop_processing #endif #ifndef QCONTAINERTOOLS_IMPL_H #define QCONTAINERTOOLS_IMPL_H #include #include QT_BEGIN_NAMESPACE namespace QtPrivate { /*! \internal Returns whether \a p is within a range [b, e). In simplest form equivalent to: b <= p < e. */ template> static constexpr bool q_points_into_range(const T *p, const T *b, const T *e, Cmp less = {}) noexcept { return !less(p, b) && less(p, e); } /*! \internal A wrapper around std::rotate(), with an optimization for Q_RELOCATABLE_TYPEs. We omit the return value, as it would be more work to compute in the Q_RELOCATABLE_TYPE case and, unlike std::rotate on ForwardIterators, callers can compute the result in constant time themselves. */ template void q_rotate(T *first, T *mid, T *last) { if (QTypeInfo::isRelocatable) { const auto cast = [](T *p) { return reinterpret_cast(p); }; std::rotate(cast(first), cast(mid), cast(last)); } else { std::rotate(first, mid, last); } } template using IfIsInputIterator = typename std::enable_if< std::is_convertible::iterator_category, std::input_iterator_tag>::value, bool>::type; template using IfIsForwardIterator = typename std::enable_if< std::is_convertible::iterator_category, std::forward_iterator_tag>::value, bool>::type; template using IfIsNotForwardIterator = typename std::enable_if< !std::is_convertible::iterator_category, std::forward_iterator_tag>::value, bool>::type; template = true> void reserveIfForwardIterator(Container *, InputIterator, InputIterator) { } template = true> void reserveIfForwardIterator(Container *c, ForwardIterator f, ForwardIterator l) { c->reserve(static_cast(std::distance(f, l))); } // for detecting expression validity template using void_t = void; template > struct AssociativeIteratorHasKeyAndValue : std::false_type { }; template struct AssociativeIteratorHasKeyAndValue< Iterator, void_t().key()), decltype(std::declval().value())> > : std::true_type { }; template , typename = void_t<>> struct AssociativeIteratorHasFirstAndSecond : std::false_type { }; template struct AssociativeIteratorHasFirstAndSecond< Iterator, void_t()->first), decltype(std::declval()->second)> > : std::true_type { }; template using IfAssociativeIteratorHasKeyAndValue = typename std::enable_if::value, bool>::type; template using IfAssociativeIteratorHasFirstAndSecond = typename std::enable_if::value, bool>::type; } // namespace QtPrivate QT_END_NAMESPACE #endif // QCONTAINERTOOLS_IMPL_H