yum-archive/TaSTT-Whisper

High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model

git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper

KonstantinSource codes8c4603c

master
2.4 KiB43 linesraw
1#pragma once
2#include <type_traits>
3
4namespace ComLight
5{
6	namespace details
7	{
8		template<class TResult, class TValue>
9		constexpr bool pointersAssignable()
10		{
11			// See this for why `&` is required: https://stackoverflow.com/a/52429468/126995
12			return std::is_assignable<TResult*&, TValue*>::value;
13		}
14	}
15}
16
17// https://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector
18#define GENERATE_HAS_MEMBER(member)                                               \
19                                                                                  \
20template < class T >                                                              \
21class HasMember_##member                                                          \
22{                                                                                 \
23private:                                                                          \
24    using Yes = char[2];                                                          \
25    using  No = char[1];                                                          \
26                                                                                  \
27    struct Fallback { int member; };                                              \
28    struct Derived : T, Fallback { };                                             \
29                                                                                  \
30    template < class U >                                                          \
31    static No& test ( decltype(U::member)* );                                     \
32    template < typename U >                                                       \
33    static Yes& test ( U* );                                                      \
34                                                                                  \
35public:                                                                           \
36    static constexpr bool RESULT = sizeof(test<Derived>(nullptr)) == sizeof(Yes); \
37};                                                                                \
38                                                                                  \
39template < class T >                                                              \
40struct has_member_##member                                                        \
41: public std::integral_constant<bool, HasMember_##member<T>::RESULT>              \
42{                                                                                 \
43};