TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
traits.h
Go to the documentation of this file.
1 #ifndef TRAITS_H
2 #define TRAITS_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Library Module project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #define TTK_DECLARE_HAS_MEMBER(__trait_name__, __member_name__) \
23  template <class T> \
24  struct __trait_name__ \
25  { \
26  typedef typename std::remove_const<T>::type check_type; \
27  struct base { void __member_name__() {}}; \
28  struct mixin : public base, public check_type {}; \
29  template <void (base::*)()> struct aux {}; \
30  template <class U> static std::false_type test(aux<&U::__member_name__>*); \
31  template <class U> static std::true_type test(...); \
32  static constexpr bool value = (sizeof(std::true_type) == sizeof(test<mixin>(0))); \
33  }
34 
35 #define TTK_DECLARE_GLOBAL_SIGNATURE(__trait_name__, __func_name__) \
36  std::nullptr_t __func_name__(...); \
37  template <class T> \
38  struct __trait_name__ \
39  { \
40  template <class U, U> struct helper; \
41  template <class U> static std::uint8_t test(helper<U*, &__func_name__>*); \
42  template <class U> static std::uint16_t test(...); \
43  static constexpr bool value = sizeof(test<T>(0)) == sizeof(std::uint8_t); \
44  }
45 
46 #define TTK_DECLARE_CLASS_SIGNATURE(__trait_name__, __func_name__) \
47  template <class Void, class Obj, class Func> \
48  struct __trait_name__ : std::false_type {}; \
49  template <class Obj, class Func> \
50  struct __trait_name__<std::void_t<decltype(static_cast<Func Obj::*>(&Obj::__func_name__))>, Obj, Func> : std::true_type {}; \
51  template <class Obj, class Func> \
52  using __trait_name__##Check = __trait_name__<void, Obj, Func>;
53 
54 #endif // TRAITS_H