File indexing completed on 2024-05-12 15:57:01
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KISCPPQUIRKS_H 0007 #define KISCPPQUIRKS_H 0008 0009 #include <type_traits> 0010 0011 namespace std { 0012 0013 // from C++14 0014 0015 // MSVC STL is C++14 by default 0016 0017 #if __cplusplus < 201402L && (!defined(_MSC_VER)) 0018 0019 template <typename Cont> 0020 inline auto rbegin(Cont &cont) -> decltype(declval<Cont>().rbegin()) { 0021 return cont.rbegin(); 0022 } 0023 0024 template <typename Cont> 0025 inline auto rend(Cont &cont) -> decltype(declval<Cont>().rend()) { 0026 return cont.rend(); 0027 } 0028 0029 template <class BidirectionalIterator> 0030 inline reverse_iterator<BidirectionalIterator> make_reverse_iterator(BidirectionalIterator x) 0031 { 0032 return reverse_iterator<BidirectionalIterator>(x); 0033 } 0034 0035 template< bool B, class T = void > 0036 using enable_if_t = typename enable_if<B,T>::type; 0037 0038 template< bool B, class T, class F > 0039 using conditional_t = typename conditional<B,T,F>::type; 0040 0041 template< class T > 0042 using add_const_t = typename add_const<T>::type; 0043 0044 0045 #endif 0046 0047 // from C++17 0048 0049 // NOTE: MSVC breaks the standard and defines these functions 0050 // even when C++14 is explicitly selected 0051 // https://github.com/microsoft/STL/issues/1925 0052 0053 #if (__cplusplus < 201703L) && (!defined(_MSC_VER)) 0054 0055 template<typename...> 0056 using void_t = void; 0057 0058 template <class T> 0059 constexpr std::add_const_t<T>& as_const(T& t) noexcept 0060 { 0061 return t; 0062 } 0063 0064 template <class T> 0065 void as_const(const T&&) = delete; 0066 0067 #endif 0068 0069 template <bool is_const, class T> 0070 struct add_const_if 0071 { 0072 using type = std::conditional_t<is_const, std::add_const_t<T>, T>; 0073 }; 0074 0075 template <bool is_const, class T> 0076 using add_const_if_t = typename add_const_if<is_const, T>::type; 0077 0078 } // namespace std 0079 0080 #if __cplusplus >= 201603L \ 0081 || defined(__has_cpp_attribute) && __has_cpp_attribute(maybe_unused) 0082 #define MAYBE_UNUSED [[maybe_unused]] 0083 #elif defined(__GNUC__) || defined(__clang__) 0084 #define MAYBE_UNUSED __attribute__((unused)) 0085 #else 0086 #define MAYBE_UNUSED 0087 #endif 0088 0089 #endif // KISCPPQUIRKS_H