Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 09:20:17

0001 // Copyright (C) 2023 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 #ifndef Q23UTILITY_H
0005 #define Q23UTILITY_H
0006 
0007 #include <QtCore/qtconfigmacros.h>
0008 
0009 #include <QtCore/q20utility.h>
0010 
0011 //
0012 //  W A R N I N G
0013 //  -------------
0014 //
0015 // This file is not part of the Qt API. Types and functions defined in this
0016 // file can reliably be replaced by their std counterparts, once available.
0017 // You may use these definitions in your own code, but be aware that we
0018 // will remove them once Qt depends on the C++ version that supports
0019 // them in namespace std. There will be NO deprecation warning, the
0020 // definitions will JUST go away.
0021 //
0022 // If you can't agree to these terms, don't use these definitions!
0023 //
0024 // We mean it.
0025 //
0026 
0027 QT_BEGIN_NAMESPACE
0028 
0029 namespace q23 {
0030 // like std::forward_like
0031 #ifdef __cpp_lib_forward_like
0032 using std::forward_like;
0033 #else
0034 
0035 namespace _detail {
0036 
0037 // [forward]/6.1 COPY_CONST
0038 template <typename A, typename B>
0039 using copy_const_t = std::conditional_t<
0040         std::is_const_v<A>, const B,
0041         /* else */          B
0042     >;
0043 
0044 // [forward]/6.2 OVERRIDE_REF
0045 template <typename A, typename B>
0046 using override_ref_t = std::conditional_t<
0047         std::is_rvalue_reference_v<A>, std::remove_reference_t<B>&&,
0048         /* else */                     B&
0049     >;
0050 
0051 // [forward]/6.3 "V"
0052 template <typename T, typename U>
0053 using forward_like_ret_t = override_ref_t<
0054         T&&,
0055         copy_const_t<
0056             std::remove_reference_t<T>,
0057             std::remove_reference_t<U>
0058         >
0059     >;
0060 
0061 } // namespace detail
0062 
0063 // http://eel.is/c++draft/forward#lib:forward_like
0064 template <class T, class U>
0065 [[nodiscard]] constexpr auto forward_like(U &&x) noexcept
0066     -> _detail::forward_like_ret_t<T, U>
0067 {
0068     using V = _detail::forward_like_ret_t<T, U>;
0069     return static_cast<V>(x);
0070 }
0071 #endif // __cpp_lib_forward_like
0072 } // namespace q23
0073 
0074 QT_END_NAMESPACE
0075 
0076 #endif /* Q23UTILITY_H */