mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 22:29:13 +08:00
refs #624 Use std alias traits.
This commit is contained in:
@@ -74,7 +74,7 @@ namespace BlackMisc
|
||||
QString CAtomicFile::randomSuffix()
|
||||
{
|
||||
constexpr auto max = 2176782335;
|
||||
return QString::number(std::uniform_int_distribution<std::decay<decltype(max)>::type>(0, max)(Private::defaultRandomGenerator()), 36);
|
||||
return QString::number(std::uniform_int_distribution<std::decay_t<decltype(max)>>(0, max)(Private::defaultRandomGenerator()), 36);
|
||||
}
|
||||
|
||||
#if defined(Q_OS_POSIX)
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Operator for streaming enums to QDBusArgument.
|
||||
*/
|
||||
template <class E, typename std::enable_if<std::is_enum<E>::value, int>::type = 0>
|
||||
template <class E, std::enable_if_t<std::is_enum<E>::value, int> = 0>
|
||||
QDBusArgument &operator <<(QDBusArgument &arg, const E &value)
|
||||
{
|
||||
arg.beginStructure();
|
||||
@@ -112,7 +112,7 @@ QDBusArgument &operator <<(QDBusArgument &arg, const E &value)
|
||||
/*!
|
||||
* Operator for streaming enums from QDBusArgument.
|
||||
*/
|
||||
template <class E, typename std::enable_if<std::is_enum<E>::value, int>::type = 0>
|
||||
template <class E, std::enable_if_t<std::is_enum<E>::value, int> = 0>
|
||||
const QDBusArgument &operator >>(const QDBusArgument &arg, E &value)
|
||||
{
|
||||
int temp;
|
||||
|
||||
@@ -26,12 +26,12 @@ namespace BlackMisc
|
||||
class BaseOf
|
||||
{
|
||||
//template <typename U> static typename U::base_type *test(int);
|
||||
template <typename U> static typename U::base_type *test(typename std::enable_if<! std::is_same<typename U::base_type, CEmpty>::value, int>::type);
|
||||
template <typename U> static typename U::base_type *test(std::enable_if_t<! std::is_same<typename U::base_type, CEmpty>::value, int>);
|
||||
template <typename U> static void *test(...);
|
||||
|
||||
public:
|
||||
//! The declared base_type of T, or void if there is none.
|
||||
typedef typename std::remove_pointer<decltype(test<T>(0))>::type type;
|
||||
using type = std::remove_pointer_t<decltype(test<T>(0))>;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -42,7 +42,7 @@ namespace BlackMisc
|
||||
{
|
||||
public:
|
||||
//! Type of T::base_type, or void if not declared.
|
||||
typedef typename std::conditional<QMetaTypeId<typename BaseOf<T>::type>::Defined, typename BaseOf<T>::type, void>::type type;
|
||||
using type = std::conditional_t<QMetaTypeId<typename BaseOf<T>::type>::Defined, typename BaseOf<T>::type, void>;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -55,7 +55,7 @@ namespace BlackMisc
|
||||
struct Empty {};
|
||||
struct Fallback { int propertyByIndex; };
|
||||
template <int Fallback:: *> struct int_t { typedef int type; };
|
||||
template <typename U> struct Derived : public Fallback, public std::conditional<std::is_void<U>::value, Empty, U>::type {};
|
||||
template <typename U> struct Derived : public Fallback, public std::conditional_t<std::is_void<U>::value, Empty, U> {};
|
||||
|
||||
template <typename U> static void test(typename int_t<&Derived<U>::propertyByIndex>::type);
|
||||
template <typename U> static U test(...);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace BlackMisc
|
||||
* By creating a CRange from such iterators, it is possible to create a container of keys without copying them.
|
||||
*/
|
||||
template <class I> class KeyIterator
|
||||
: public std::iterator<std::bidirectional_iterator_tag, typename std::decay<decltype(std::declval<I>().key())>::type>
|
||||
: public std::iterator<std::bidirectional_iterator_tag, std::decay_t<decltype(std::declval<I>().key())>>
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
@@ -81,7 +81,7 @@ namespace BlackMisc
|
||||
*/
|
||||
template <class I, class F> class TransformIterator
|
||||
: public std::iterator<std::input_iterator_tag,
|
||||
typename std::decay<decltype(std::declval<F>()(std::declval<typename std::iterator_traits<I>::value_type>()))>::type>
|
||||
std::decay_t<decltype(std::declval<F>()(std::declval<typename std::iterator_traits<I>::value_type>()))>>
|
||||
{
|
||||
public:
|
||||
//! The type returned by the transformation function, which may or may not be a reference.
|
||||
@@ -90,17 +90,17 @@ namespace BlackMisc
|
||||
//! \private A pointer-like wrapper returned by the arrow operator if the transformation function returns by value.
|
||||
struct PointerWrapper
|
||||
{
|
||||
PointerWrapper(typename std::decay<undecayed_type>::type *obj) : m_obj(std::move(*obj)) {}
|
||||
typename std::decay<undecayed_type>::type const *operator ->() const { return &m_obj; }
|
||||
typename std::decay<undecayed_type>::type operator *() const & { return m_obj; }
|
||||
typename std::decay<undecayed_type>::type operator *() && { return std::move(m_obj); }
|
||||
PointerWrapper(std::decay_t<undecayed_type> *obj) : m_obj(std::move(*obj)) {}
|
||||
std::decay_t<undecayed_type> const *operator ->() const { return &m_obj; }
|
||||
std::decay_t<undecayed_type> operator *() const & { return m_obj; }
|
||||
std::decay_t<undecayed_type> operator *() && { return std::move(m_obj); }
|
||||
private:
|
||||
const typename std::decay<undecayed_type>::type m_obj;
|
||||
const std::decay_t<undecayed_type> m_obj;
|
||||
};
|
||||
|
||||
//! The type returned by this iterator's arrow operator, which may be a pointer or a pointer-like wrapper object
|
||||
using pointer = typename std::conditional<std::is_reference<undecayed_type>::value,
|
||||
typename std::remove_reference<undecayed_type>::type *,
|
||||
std::remove_reference_t<undecayed_type> *,
|
||||
PointerWrapper>::type;
|
||||
|
||||
//! Constructor.
|
||||
|
||||
@@ -63,8 +63,8 @@ BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, QBy
|
||||
//! \brief Specialized JSON serialization for enum
|
||||
//! \remarks needs to be in global namespace
|
||||
//! \ingroup JSON
|
||||
template<class ENUM> typename
|
||||
std::enable_if<std::is_enum<ENUM>::value, QJsonObject>::type
|
||||
template<class ENUM>
|
||||
std::enable_if_t<std::is_enum<ENUM>::value, QJsonObject>
|
||||
&operator<<(QJsonObject &json, std::pair<QString, const ENUM &> value)
|
||||
{
|
||||
json.insert(value.first, QJsonValue(static_cast<int>(value.second)));
|
||||
@@ -73,8 +73,8 @@ std::enable_if<std::is_enum<ENUM>::value, QJsonObject>::type
|
||||
|
||||
//! \brief Specialized JSON deserialization for enum
|
||||
//! \ingroup JSON
|
||||
template<class ENUM> typename
|
||||
std::enable_if<std::is_enum<ENUM>::value, QJsonValue>::type
|
||||
template<class ENUM>
|
||||
std::enable_if_t<std::is_enum<ENUM>::value, QJsonValue>
|
||||
const &operator>>(const QJsonValue &json, ENUM &value)
|
||||
{
|
||||
value = static_cast<ENUM>(json.toInt());
|
||||
@@ -83,8 +83,8 @@ const &operator>>(const QJsonValue &json, ENUM &value)
|
||||
|
||||
//! \brief Specialized JSON deserialization for enum
|
||||
//! \ingroup JSON
|
||||
template<class ENUM> typename
|
||||
std::enable_if<std::is_enum<ENUM>::value, QJsonValueRef>::type
|
||||
template<class ENUM>
|
||||
std::enable_if_t<std::is_enum<ENUM>::value, QJsonValueRef>
|
||||
const &operator>>(const QJsonValueRef &json, ENUM &value)
|
||||
{
|
||||
value = static_cast<ENUM>(json.toInt());
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace BlackMisc
|
||||
LockFreeReader &operator =(const LockFreeReader &) = default;
|
||||
|
||||
private:
|
||||
friend class LockFree<typename std::remove_const<T>::type>;
|
||||
friend class LockFree<std::remove_const_t<T>>;
|
||||
|
||||
LockFreeReader(std::shared_ptr<const T> ptr) : m_ptr(ptr) {}
|
||||
std::shared_ptr<const T> m_ptr;
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace BlackMisc
|
||||
* \param pointer The value of pointer is unimportant. Only the static type T is considered.
|
||||
* It is legal to pass static_cast<T>(nullptr), but in member functions passing the <tt>this</tt> pointer is easier.
|
||||
*/
|
||||
template <typename T, typename = typename std::enable_if<std::is_class<T>::value>::type>
|
||||
template <typename T, typename = std::enable_if_t<std::is_class<T>::value>>
|
||||
CLogCategoryList(const T *pointer) : CLogCategoryList(fromClass<T>()) { Q_UNUSED(pointer); }
|
||||
|
||||
//! Convert each of the categories to a QString and return the result as a QStringList.
|
||||
|
||||
@@ -66,14 +66,14 @@ namespace BlackMisc
|
||||
const Derived *derived() const { return static_cast<const Derived *>(this); }
|
||||
Derived *derived() { return static_cast<Derived *>(this); }
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_default_constructible<T>::value, int>::type = 0>
|
||||
template <typename T, std::enable_if_t<std::is_default_constructible<T>::value, int> = 0>
|
||||
CVariant myself() const { return CVariant::from(*derived()); }
|
||||
template <typename T, typename std::enable_if<std::is_default_constructible<T>::value, int>::type = 0>
|
||||
template <typename T, std::enable_if_t<std::is_default_constructible<T>::value, int> = 0>
|
||||
void myself(const CVariant &variant) { *derived() = variant.to<T>(); }
|
||||
|
||||
template <typename T, typename std::enable_if<! std::is_default_constructible<T>::value, int>::type = 0>
|
||||
template <typename T, std::enable_if_t<! std::is_default_constructible<T>::value, int> = 0>
|
||||
CVariant myself() const { qFatal("isMyself should have been handled before reaching here"); return {}; }
|
||||
template <typename T, typename std::enable_if<! std::is_default_constructible<T>::value, int>::type = 0>
|
||||
template <typename T, std::enable_if_t<! std::is_default_constructible<T>::value, int> = 0>
|
||||
void myself(const CVariant &) { qFatal("isMyself should have been handled before reaching here"); }
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BlackMisc
|
||||
*/
|
||||
//! @{
|
||||
template <class T>
|
||||
constexpr typename std::add_const<T>::type &as_const(T &v) noexcept { return v; }
|
||||
constexpr std::add_const_t<T> &as_const(T &v) noexcept { return v; }
|
||||
template <class T>
|
||||
void as_const(const T &&) = delete;
|
||||
//! @}
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace BlackMisc
|
||||
Derived &operator <<(QChar v) { return arg(v); }
|
||||
Derived &operator <<(char v) { return arg(QChar(v)); }
|
||||
Derived &operator <<(double v) { return arg(QString::number(v)); }
|
||||
template <class T, class = typename std::enable_if<HasToQString<T>::value>::type>
|
||||
template <class T, class = std::enable_if_t<HasToQString<T>::value>>
|
||||
Derived &operator <<(const T &v) { return arg(v.toQString()); }
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace BlackMisc
|
||||
void extendMetaTuple(Tu &&tu) const
|
||||
{
|
||||
Private::extendMeta(std::forward<Tu>(tu), m_names,
|
||||
Private::make_index_sequence<std::tuple_size<typename std::decay<Tu>::type>::value>());
|
||||
Private::make_index_sequence<std::tuple_size<std::decay_t<Tu>>::value>());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace BlackMisc
|
||||
template <class T>
|
||||
static auto toMetaTuple(T &o)
|
||||
{
|
||||
return TupleConverter<typename std::decay<T>::type>::toMetaTuple(o);
|
||||
return TupleConverter<std::decay_t<T>>::toMetaTuple(o);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -107,24 +107,24 @@ namespace BlackMisc
|
||||
{
|
||||
typedef Tu tuple_type;
|
||||
template <size_t I>
|
||||
struct test : std::integral_constant<bool, bool(std::tuple_element<I, Tu>::type::flags & F)> {};
|
||||
struct test : std::integral_constant<bool, bool(std::tuple_element_t<I, Tu>::flags & F)> {};
|
||||
};
|
||||
template <qint64 F, class Tu>
|
||||
struct FlagMissing
|
||||
{
|
||||
typedef Tu tuple_type;
|
||||
template <size_t I>
|
||||
struct test : std::integral_constant<bool, ! bool(std::tuple_element<I, Tu>::type::flags & F)> {};
|
||||
struct test : std::integral_constant<bool, ! bool(std::tuple_element_t<I, Tu>::flags & F)> {};
|
||||
};
|
||||
|
||||
// Combine make_index_sequence_if with predicates to get the indices of tuple elements with certain flags.
|
||||
template <qint64 F, class Tu>
|
||||
auto findFlaggedIndices(Tu &&) -> make_index_sequence_if<FlagPresent<F, typename std::decay<Tu>::type>>
|
||||
auto findFlaggedIndices(Tu &&) -> make_index_sequence_if<FlagPresent<F, std::decay_t<Tu>>>
|
||||
{
|
||||
return {};
|
||||
}
|
||||
template <qint64 F, class Tu>
|
||||
auto skipFlaggedIndices(Tu &&) -> make_index_sequence_if<FlagMissing<F, typename std::decay<Tu>::type>>
|
||||
auto skipFlaggedIndices(Tu &&) -> make_index_sequence_if<FlagMissing<F, std::decay_t<Tu>>>
|
||||
{
|
||||
return {};
|
||||
}
|
||||
@@ -318,9 +318,9 @@ namespace BlackMisc
|
||||
marshallHelper(arg, head, 0);
|
||||
marshallImpl(arg, tail...);
|
||||
}
|
||||
template <class T, typename std::enable_if<std::is_base_of<CEmpty, T>::value, int>::type = 0>
|
||||
template <class T, std::enable_if_t<std::is_base_of<CEmpty, T>::value, int> = 0>
|
||||
static void marshallHelper(QDBusArgument &arg, const T &val, int) { static_cast<const typename T::CValueObject &>(val).marshallToDbus(arg); }
|
||||
template <class T, typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
|
||||
template <class T, std::enable_if_t<std::is_enum<T>::value, int> = 0>
|
||||
static void marshallHelper(QDBusArgument &arg, const T &val, int) { arg << static_cast<int>(val); }
|
||||
template <class T>
|
||||
static void marshallHelper(QDBusArgument &arg, const T &val, ...) { arg << val; }
|
||||
@@ -332,9 +332,9 @@ namespace BlackMisc
|
||||
unmarshallHelper(arg, head, 0);
|
||||
unmarshallImpl(arg, tail...);
|
||||
}
|
||||
template <class T, typename std::enable_if<std::is_base_of<CEmpty, T>::value, int>::type = 0>
|
||||
template <class T, std::enable_if_t<std::is_base_of<CEmpty, T>::value, int> = 0>
|
||||
static void unmarshallHelper(const QDBusArgument &arg, T &val, int) { static_cast<typename T::CValueObject &>(val).unmarshallFromDbus(arg); }
|
||||
template <class T, typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
|
||||
template <class T, std::enable_if_t<std::is_enum<T>::value, int> = 0>
|
||||
static void unmarshallHelper(const QDBusArgument &arg, T &val, int) { int i; arg >> i; val = static_cast<T>(i); }
|
||||
template <class T>
|
||||
static void unmarshallHelper(const QDBusArgument &arg, T &val, ...) { arg >> val; }
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace BlackMisc
|
||||
//! \private
|
||||
template <typename T, typename... Ts> struct DecayFirst<T, Ts...>
|
||||
{
|
||||
typedef typename std::decay<T>::type type;
|
||||
using type = std::decay_t<T>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -182,14 +182,14 @@ namespace BlackMisc
|
||||
//! Construct a variant from a value.
|
||||
template <typename T> static CVariant fromValue(T &&value)
|
||||
{
|
||||
static_assert(!std::is_same<CVariant, typename std::decay<T>::type>::value, "CVariant is an illegal type!");
|
||||
static_assert(!std::is_same<CVariant, std::decay_t<T>>::value, "CVariant is an illegal type!");
|
||||
return CVariant(QVariant::fromValue(std::forward<T>(value)));
|
||||
}
|
||||
|
||||
//! Synonym for fromValue().
|
||||
template <typename T> static CVariant from(T &&value)
|
||||
{
|
||||
static_assert(!std::is_same<CVariant, typename std::decay<T>::type>::value, "CVariant is an illegal type!");
|
||||
static_assert(!std::is_same<CVariant, std::decay_t<T>>::value, "CVariant is an illegal type!");
|
||||
return CVariant(QVariant::fromValue(std::forward<T>(value)));
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace BlackMisc
|
||||
template <typename U> static bool equalsPropertyByIndexHelper(const U &object, const CVariant &, const CPropertyIndex &, DISABLE_IF_HAS(equalsPropertyByIndex)) { throw CVariantException(object, "equalsPropertyByIndex"); }
|
||||
template <typename U> static bool equalsPropertyByIndexHelper(const U &object, const CVariant &variant, const CPropertyIndex &index, ...) { return object.equalsPropertyByIndex(variant, index); }
|
||||
template <typename U> static void toIconHelper(const U &object, CIcon &, DISABLE_IF_HAS(toIcon)) { throw CVariantException(object, "toIcon"); }
|
||||
template <typename U> static void toIconHelper(const U &object, CIcon &, typename std::enable_if<std::is_same<U, CVariant>::value, int>::type) { throw CVariantException(object, "toIcon"); } // CIcon is incomplete when CValueObjectMetaInfo<CVariant> is instantiated
|
||||
template <typename U> static void toIconHelper(const U &object, CIcon &, std::enable_if_t<std::is_same<U, CVariant>::value, int>) { throw CVariantException(object, "toIcon"); } // CIcon is incomplete when CValueObjectMetaInfo<CVariant> is instantiated
|
||||
template <typename U> static void toIconHelper(const U &object, CIcon &o_icon, ...) { assign(o_icon, object.toIcon()); }
|
||||
|
||||
# undef DISABLE_IF_HAS
|
||||
|
||||
@@ -187,14 +187,14 @@ namespace BlackMisc
|
||||
|
||||
//! Uniform way to invoke either a functor or a method.
|
||||
template <typename T, typename F, typename... Ts>
|
||||
static auto invoke(T *object, F func, Ts &&... args) -> typename std::enable_if<std::is_member_function_pointer<F>::value>::type
|
||||
static auto invoke(T *object, F func, Ts &&... args) -> std::enable_if_t<std::is_member_function_pointer<F>::value>
|
||||
{
|
||||
return (object->*func)(std::forward<Ts>(args)...);
|
||||
}
|
||||
|
||||
//! Uniform way to invoke either a functor or a method.
|
||||
template <typename T, typename F, typename... Ts>
|
||||
static auto invoke(T *, F func, Ts &&... args) -> typename std::enable_if<! std::is_member_function_pointer<F>::value>::type
|
||||
static auto invoke(T *, F func, Ts &&... args) -> std::enable_if_t<! std::is_member_function_pointer<F>::value>
|
||||
{
|
||||
return func(std::forward<Ts>(args)...);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user