webrtcvad 0.1.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/ext/webrtcvad/extconf.rb +29 -0
  3. data/ext/webrtcvad/webrtc/common_audio/signal_processing/division_operations.c +141 -0
  4. data/ext/webrtcvad/webrtc/common_audio/signal_processing/dot_product_with_scale.h +40 -0
  5. data/ext/webrtcvad/webrtc/common_audio/signal_processing/energy.c +39 -0
  6. data/ext/webrtcvad/webrtc/common_audio/signal_processing/get_scaling_square.c +46 -0
  7. data/ext/webrtcvad/webrtc/common_audio/signal_processing/include/signal_processing_library.h +1605 -0
  8. data/ext/webrtcvad/webrtc/common_audio/signal_processing/include/spl_inl.h +153 -0
  9. data/ext/webrtcvad/webrtc/common_audio/signal_processing/resample_48khz.c +186 -0
  10. data/ext/webrtcvad/webrtc/common_audio/signal_processing/resample_by_2_internal.c +689 -0
  11. data/ext/webrtcvad/webrtc/common_audio/signal_processing/resample_by_2_internal.h +60 -0
  12. data/ext/webrtcvad/webrtc/common_audio/signal_processing/resample_fractional.c +239 -0
  13. data/ext/webrtcvad/webrtc/common_audio/third_party/spl_sqrt_floor/spl_sqrt_floor.c +77 -0
  14. data/ext/webrtcvad/webrtc/common_audio/third_party/spl_sqrt_floor/spl_sqrt_floor.h +29 -0
  15. data/ext/webrtcvad/webrtc/common_audio/third_party/spl_sqrt_floor/spl_sqrt_floor_mips.c +207 -0
  16. data/ext/webrtcvad/webrtc/common_audio/vad/include/webrtc_vad.h +87 -0
  17. data/ext/webrtcvad/webrtc/common_audio/vad/vad_core.c +685 -0
  18. data/ext/webrtcvad/webrtc/common_audio/vad/vad_core.h +114 -0
  19. data/ext/webrtcvad/webrtc/common_audio/vad/vad_filterbank.c +329 -0
  20. data/ext/webrtcvad/webrtc/common_audio/vad/vad_filterbank.h +45 -0
  21. data/ext/webrtcvad/webrtc/common_audio/vad/vad_gmm.c +82 -0
  22. data/ext/webrtcvad/webrtc/common_audio/vad/vad_gmm.h +39 -0
  23. data/ext/webrtcvad/webrtc/common_audio/vad/vad_sp.c +176 -0
  24. data/ext/webrtcvad/webrtc/common_audio/vad/vad_sp.h +54 -0
  25. data/ext/webrtcvad/webrtc/common_audio/vad/webrtc_vad.c +114 -0
  26. data/ext/webrtcvad/webrtc/rtc_base/checks.cc +207 -0
  27. data/ext/webrtcvad/webrtc/rtc_base/checks.h +400 -0
  28. data/ext/webrtcvad/webrtc/rtc_base/compile_assert_c.h +25 -0
  29. data/ext/webrtcvad/webrtc/rtc_base/numerics/safe_compare.h +176 -0
  30. data/ext/webrtcvad/webrtc/rtc_base/sanitizer.h +144 -0
  31. data/ext/webrtcvad/webrtc/rtc_base/system/inline.h +31 -0
  32. data/ext/webrtcvad/webrtc/rtc_base/system/rtc_export.h +43 -0
  33. data/ext/webrtcvad/webrtc/rtc_base/type_traits.h +140 -0
  34. data/ext/webrtcvad/webrtcvad.c +112 -0
  35. metadata +37 -3
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #ifndef RTC_BASE_COMPILE_ASSERT_C_H_
12
+ #define RTC_BASE_COMPILE_ASSERT_C_H_
13
+
14
+ // Use this macro to verify at compile time that certain restrictions are met.
15
+ // The argument is the boolean expression to evaluate.
16
+ // Example:
17
+ // RTC_COMPILE_ASSERT(sizeof(foo) < 128);
18
+ // Note: In C++, use static_assert instead!
19
+ #define RTC_COMPILE_ASSERT(expression) \
20
+ switch (0) { \
21
+ case 0: \
22
+ case expression:; \
23
+ }
24
+
25
+ #endif // RTC_BASE_COMPILE_ASSERT_C_H_
@@ -0,0 +1,176 @@
1
+ /*
2
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ // This file defines six constexpr functions:
12
+ //
13
+ // rtc::SafeEq // ==
14
+ // rtc::SafeNe // !=
15
+ // rtc::SafeLt // <
16
+ // rtc::SafeLe // <=
17
+ // rtc::SafeGt // >
18
+ // rtc::SafeGe // >=
19
+ //
20
+ // They each accept two arguments of arbitrary types, and in almost all cases,
21
+ // they simply call the appropriate comparison operator. However, if both
22
+ // arguments are integers, they don't compare them using C++'s quirky rules,
23
+ // but instead adhere to the true mathematical definitions. It is as if the
24
+ // arguments were first converted to infinite-range signed integers, and then
25
+ // compared, although of course nothing expensive like that actually takes
26
+ // place. In practice, for signed/signed and unsigned/unsigned comparisons and
27
+ // some mixed-signed comparisons with a compile-time constant, the overhead is
28
+ // zero; in the remaining cases, it is just a few machine instructions (no
29
+ // branches).
30
+
31
+ #ifndef RTC_BASE_NUMERICS_SAFE_COMPARE_H_
32
+ #define RTC_BASE_NUMERICS_SAFE_COMPARE_H_
33
+
34
+ #include <stddef.h>
35
+ #include <stdint.h>
36
+
37
+ #include <type_traits>
38
+ #include <utility>
39
+
40
+ #include "rtc_base/type_traits.h"
41
+
42
+ namespace rtc {
43
+
44
+ namespace safe_cmp_impl {
45
+
46
+ template <size_t N>
47
+ struct LargerIntImpl : std::false_type {};
48
+ template <>
49
+ struct LargerIntImpl<sizeof(int8_t)> : std::true_type {
50
+ using type = int16_t;
51
+ };
52
+ template <>
53
+ struct LargerIntImpl<sizeof(int16_t)> : std::true_type {
54
+ using type = int32_t;
55
+ };
56
+ template <>
57
+ struct LargerIntImpl<sizeof(int32_t)> : std::true_type {
58
+ using type = int64_t;
59
+ };
60
+
61
+ // LargerInt<T1, T2>::value is true iff there's a signed type that's larger
62
+ // than T1 (and no larger than the larger of T2 and int*, for performance
63
+ // reasons); and if there is such a type, LargerInt<T1, T2>::type is an alias
64
+ // for it.
65
+ template <typename T1, typename T2>
66
+ struct LargerInt
67
+ : LargerIntImpl<sizeof(T1) < sizeof(T2) || sizeof(T1) < sizeof(int*)
68
+ ? sizeof(T1)
69
+ : 0> {};
70
+
71
+ template <typename T>
72
+ constexpr typename std::make_unsigned<T>::type MakeUnsigned(T a) {
73
+ return static_cast<typename std::make_unsigned<T>::type>(a);
74
+ }
75
+
76
+ // Overload for when both T1 and T2 have the same signedness.
77
+ template <typename Op,
78
+ typename T1,
79
+ typename T2,
80
+ typename std::enable_if<std::is_signed<T1>::value ==
81
+ std::is_signed<T2>::value>::type* = nullptr>
82
+ constexpr bool Cmp(T1 a, T2 b) {
83
+ return Op::Op(a, b);
84
+ }
85
+
86
+ // Overload for signed - unsigned comparison that can be promoted to a bigger
87
+ // signed type.
88
+ template <typename Op,
89
+ typename T1,
90
+ typename T2,
91
+ typename std::enable_if<std::is_signed<T1>::value &&
92
+ std::is_unsigned<T2>::value &&
93
+ LargerInt<T2, T1>::value>::type* = nullptr>
94
+ constexpr bool Cmp(T1 a, T2 b) {
95
+ return Op::Op(a, static_cast<typename LargerInt<T2, T1>::type>(b));
96
+ }
97
+
98
+ // Overload for unsigned - signed comparison that can be promoted to a bigger
99
+ // signed type.
100
+ template <typename Op,
101
+ typename T1,
102
+ typename T2,
103
+ typename std::enable_if<std::is_unsigned<T1>::value &&
104
+ std::is_signed<T2>::value &&
105
+ LargerInt<T1, T2>::value>::type* = nullptr>
106
+ constexpr bool Cmp(T1 a, T2 b) {
107
+ return Op::Op(static_cast<typename LargerInt<T1, T2>::type>(a), b);
108
+ }
109
+
110
+ // Overload for signed - unsigned comparison that can't be promoted to a bigger
111
+ // signed type.
112
+ template <typename Op,
113
+ typename T1,
114
+ typename T2,
115
+ typename std::enable_if<std::is_signed<T1>::value &&
116
+ std::is_unsigned<T2>::value &&
117
+ !LargerInt<T2, T1>::value>::type* = nullptr>
118
+ constexpr bool Cmp(T1 a, T2 b) {
119
+ return a < 0 ? Op::Op(-1, 0) : Op::Op(safe_cmp_impl::MakeUnsigned(a), b);
120
+ }
121
+
122
+ // Overload for unsigned - signed comparison that can't be promoted to a bigger
123
+ // signed type.
124
+ template <typename Op,
125
+ typename T1,
126
+ typename T2,
127
+ typename std::enable_if<std::is_unsigned<T1>::value &&
128
+ std::is_signed<T2>::value &&
129
+ !LargerInt<T1, T2>::value>::type* = nullptr>
130
+ constexpr bool Cmp(T1 a, T2 b) {
131
+ return b < 0 ? Op::Op(0, -1) : Op::Op(a, safe_cmp_impl::MakeUnsigned(b));
132
+ }
133
+
134
+ #define RTC_SAFECMP_MAKE_OP(name, op) \
135
+ struct name { \
136
+ template <typename T1, typename T2> \
137
+ static constexpr bool Op(T1 a, T2 b) { \
138
+ return a op b; \
139
+ } \
140
+ };
141
+ RTC_SAFECMP_MAKE_OP(EqOp, ==)
142
+ RTC_SAFECMP_MAKE_OP(NeOp, !=)
143
+ RTC_SAFECMP_MAKE_OP(LtOp, <)
144
+ RTC_SAFECMP_MAKE_OP(LeOp, <=)
145
+ RTC_SAFECMP_MAKE_OP(GtOp, >)
146
+ RTC_SAFECMP_MAKE_OP(GeOp, >=)
147
+ #undef RTC_SAFECMP_MAKE_OP
148
+
149
+ } // namespace safe_cmp_impl
150
+
151
+ #define RTC_SAFECMP_MAKE_FUN(name) \
152
+ template <typename T1, typename T2> \
153
+ constexpr \
154
+ typename std::enable_if<IsIntlike<T1>::value && IsIntlike<T2>::value, \
155
+ bool>::type Safe##name(T1 a, T2 b) { \
156
+ /* Unary plus here turns enums into real integral types. */ \
157
+ return safe_cmp_impl::Cmp<safe_cmp_impl::name##Op>(+a, +b); \
158
+ } \
159
+ template <typename T1, typename T2> \
160
+ constexpr \
161
+ typename std::enable_if<!IsIntlike<T1>::value || !IsIntlike<T2>::value, \
162
+ bool>::type Safe##name(const T1& a, \
163
+ const T2& b) { \
164
+ return safe_cmp_impl::name##Op::Op(a, b); \
165
+ }
166
+ RTC_SAFECMP_MAKE_FUN(Eq)
167
+ RTC_SAFECMP_MAKE_FUN(Ne)
168
+ RTC_SAFECMP_MAKE_FUN(Lt)
169
+ RTC_SAFECMP_MAKE_FUN(Le)
170
+ RTC_SAFECMP_MAKE_FUN(Gt)
171
+ RTC_SAFECMP_MAKE_FUN(Ge)
172
+ #undef RTC_SAFECMP_MAKE_FUN
173
+
174
+ } // namespace rtc
175
+
176
+ #endif // RTC_BASE_NUMERICS_SAFE_COMPARE_H_
@@ -0,0 +1,144 @@
1
+ /*
2
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #ifndef RTC_BASE_SANITIZER_H_
12
+ #define RTC_BASE_SANITIZER_H_
13
+
14
+ #include <stddef.h> // For size_t.
15
+
16
+ #ifdef __cplusplus
17
+ #include "absl/meta/type_traits.h"
18
+ #endif
19
+
20
+ #if defined(__has_feature)
21
+ #if __has_feature(address_sanitizer)
22
+ #define RTC_HAS_ASAN 1
23
+ #endif
24
+ #if __has_feature(memory_sanitizer)
25
+ #define RTC_HAS_MSAN 1
26
+ #endif
27
+ #endif
28
+ #ifndef RTC_HAS_ASAN
29
+ #define RTC_HAS_ASAN 0
30
+ #endif
31
+ #ifndef RTC_HAS_MSAN
32
+ #define RTC_HAS_MSAN 0
33
+ #endif
34
+
35
+ #if RTC_HAS_ASAN
36
+ #include <sanitizer/asan_interface.h>
37
+ #endif
38
+ #if RTC_HAS_MSAN
39
+ #include <sanitizer/msan_interface.h>
40
+ #endif
41
+
42
+ #ifdef __has_attribute
43
+ #if __has_attribute(no_sanitize)
44
+ #define RTC_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
45
+ #endif
46
+ #endif
47
+ #ifndef RTC_NO_SANITIZE
48
+ #define RTC_NO_SANITIZE(what)
49
+ #endif
50
+
51
+ // Ask ASan to mark the memory range [ptr, ptr + element_size * num_elements)
52
+ // as being unaddressable, so that reads and writes are not allowed. ASan may
53
+ // narrow the range to the nearest alignment boundaries.
54
+ static inline void rtc_AsanPoison(const volatile void* ptr,
55
+ size_t element_size,
56
+ size_t num_elements) {
57
+ #if RTC_HAS_ASAN
58
+ ASAN_POISON_MEMORY_REGION(ptr, element_size * num_elements);
59
+ #endif
60
+ }
61
+
62
+ // Ask ASan to mark the memory range [ptr, ptr + element_size * num_elements)
63
+ // as being addressable, so that reads and writes are allowed. ASan may widen
64
+ // the range to the nearest alignment boundaries.
65
+ static inline void rtc_AsanUnpoison(const volatile void* ptr,
66
+ size_t element_size,
67
+ size_t num_elements) {
68
+ #if RTC_HAS_ASAN
69
+ ASAN_UNPOISON_MEMORY_REGION(ptr, element_size * num_elements);
70
+ #endif
71
+ }
72
+
73
+ // Ask MSan to mark the memory range [ptr, ptr + element_size * num_elements)
74
+ // as being uninitialized.
75
+ static inline void rtc_MsanMarkUninitialized(const volatile void* ptr,
76
+ size_t element_size,
77
+ size_t num_elements) {
78
+ #if RTC_HAS_MSAN
79
+ __msan_poison(ptr, element_size * num_elements);
80
+ #endif
81
+ }
82
+
83
+ // Force an MSan check (if any bits in the memory range [ptr, ptr +
84
+ // element_size * num_elements) are uninitialized the call will crash with an
85
+ // MSan report).
86
+ static inline void rtc_MsanCheckInitialized(const volatile void* ptr,
87
+ size_t element_size,
88
+ size_t num_elements) {
89
+ #if RTC_HAS_MSAN
90
+ __msan_check_mem_is_initialized(ptr, element_size * num_elements);
91
+ #endif
92
+ }
93
+
94
+ #ifdef __cplusplus
95
+
96
+ namespace rtc {
97
+ namespace sanitizer_impl {
98
+
99
+ template <typename T>
100
+ constexpr bool IsTriviallyCopyable() {
101
+ return static_cast<bool>(absl::is_trivially_copy_constructible<T>::value &&
102
+ (absl::is_trivially_copy_assignable<T>::value ||
103
+ !std::is_copy_assignable<T>::value) &&
104
+ absl::is_trivially_destructible<T>::value);
105
+ }
106
+
107
+ } // namespace sanitizer_impl
108
+
109
+ template <typename T>
110
+ inline void AsanPoison(const T& mem) {
111
+ rtc_AsanPoison(mem.data(), sizeof(mem.data()[0]), mem.size());
112
+ }
113
+
114
+ template <typename T>
115
+ inline void AsanUnpoison(const T& mem) {
116
+ rtc_AsanUnpoison(mem.data(), sizeof(mem.data()[0]), mem.size());
117
+ }
118
+
119
+ template <typename T>
120
+ inline void MsanMarkUninitialized(const T& mem) {
121
+ rtc_MsanMarkUninitialized(mem.data(), sizeof(mem.data()[0]), mem.size());
122
+ }
123
+
124
+ template <typename T>
125
+ inline T MsanUninitialized(T t) {
126
+ #if RTC_HAS_MSAN
127
+ // TODO(bugs.webrtc.org/8762): Switch to std::is_trivially_copyable when it
128
+ // becomes available in downstream projects.
129
+ static_assert(sanitizer_impl::IsTriviallyCopyable<T>(), "");
130
+ #endif
131
+ rtc_MsanMarkUninitialized(&t, sizeof(T), 1);
132
+ return t;
133
+ }
134
+
135
+ template <typename T>
136
+ inline void MsanCheckInitialized(const T& mem) {
137
+ rtc_MsanCheckInitialized(mem.data(), sizeof(mem.data()[0]), mem.size());
138
+ }
139
+
140
+ } // namespace rtc
141
+
142
+ #endif // __cplusplus
143
+
144
+ #endif // RTC_BASE_SANITIZER_H_
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #ifndef RTC_BASE_SYSTEM_INLINE_H_
12
+ #define RTC_BASE_SYSTEM_INLINE_H_
13
+
14
+ #if defined(_MSC_VER)
15
+
16
+ #define RTC_FORCE_INLINE __forceinline
17
+ #define RTC_NO_INLINE __declspec(noinline)
18
+
19
+ #elif defined(__GNUC__)
20
+
21
+ #define RTC_FORCE_INLINE __attribute__((__always_inline__))
22
+ #define RTC_NO_INLINE __attribute__((__noinline__))
23
+
24
+ #else
25
+
26
+ #define RTC_FORCE_INLINE
27
+ #define RTC_NO_INLINE
28
+
29
+ #endif
30
+
31
+ #endif // RTC_BASE_SYSTEM_INLINE_H_
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #ifndef RTC_BASE_SYSTEM_RTC_EXPORT_H_
12
+ #define RTC_BASE_SYSTEM_RTC_EXPORT_H_
13
+
14
+ // RTC_EXPORT is used to mark symbols as exported or imported when WebRTC is
15
+ // built or used as a shared library.
16
+ // When WebRTC is built as a static library the RTC_EXPORT macro expands to
17
+ // nothing.
18
+
19
+ #ifdef WEBRTC_ENABLE_SYMBOL_EXPORT
20
+
21
+ #ifdef WEBRTC_WIN
22
+
23
+ #ifdef WEBRTC_LIBRARY_IMPL
24
+ #define RTC_EXPORT __declspec(dllexport)
25
+ #else
26
+ #define RTC_EXPORT __declspec(dllimport)
27
+ #endif
28
+
29
+ #else // WEBRTC_WIN
30
+
31
+ #if __has_attribute(visibility) && defined(WEBRTC_LIBRARY_IMPL)
32
+ #define RTC_EXPORT __attribute__((visibility("default")))
33
+ #endif
34
+
35
+ #endif // WEBRTC_WIN
36
+
37
+ #endif // WEBRTC_ENABLE_SYMBOL_EXPORT
38
+
39
+ #ifndef RTC_EXPORT
40
+ #define RTC_EXPORT
41
+ #endif
42
+
43
+ #endif // RTC_BASE_SYSTEM_RTC_EXPORT_H_
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #ifndef RTC_BASE_TYPE_TRAITS_H_
12
+ #define RTC_BASE_TYPE_TRAITS_H_
13
+
14
+ #include <cstddef>
15
+ #include <type_traits>
16
+
17
+ namespace rtc {
18
+
19
+ // Determines if the given class has zero-argument .data() and .size() methods
20
+ // whose return values are convertible to T* and size_t, respectively.
21
+ template <typename DS, typename T>
22
+ class HasDataAndSize {
23
+ private:
24
+ template <
25
+ typename C,
26
+ typename std::enable_if<
27
+ std::is_convertible<decltype(std::declval<C>().data()), T*>::value &&
28
+ std::is_convertible<decltype(std::declval<C>().size()),
29
+ std::size_t>::value>::type* = nullptr>
30
+ static int Test(int);
31
+
32
+ template <typename>
33
+ static char Test(...);
34
+
35
+ public:
36
+ static constexpr bool value = std::is_same<decltype(Test<DS>(0)), int>::value;
37
+ };
38
+
39
+ namespace test_has_data_and_size {
40
+
41
+ template <typename DR, typename SR>
42
+ struct Test1 {
43
+ DR data();
44
+ SR size();
45
+ };
46
+ static_assert(HasDataAndSize<Test1<int*, int>, int>::value, "");
47
+ static_assert(HasDataAndSize<Test1<int*, int>, const int>::value, "");
48
+ static_assert(HasDataAndSize<Test1<const int*, int>, const int>::value, "");
49
+ static_assert(!HasDataAndSize<Test1<const int*, int>, int>::value,
50
+ "implicit cast of const int* to int*");
51
+ static_assert(!HasDataAndSize<Test1<char*, size_t>, int>::value,
52
+ "implicit cast of char* to int*");
53
+
54
+ struct Test2 {
55
+ int* data;
56
+ size_t size;
57
+ };
58
+ static_assert(!HasDataAndSize<Test2, int>::value,
59
+ ".data and .size aren't functions");
60
+
61
+ struct Test3 {
62
+ int* data();
63
+ };
64
+ static_assert(!HasDataAndSize<Test3, int>::value, ".size() is missing");
65
+
66
+ class Test4 {
67
+ int* data();
68
+ size_t size();
69
+ };
70
+ static_assert(!HasDataAndSize<Test4, int>::value,
71
+ ".data() and .size() are private");
72
+
73
+ } // namespace test_has_data_and_size
74
+
75
+ namespace type_traits_impl {
76
+
77
+ // Determines if the given type is an enum that converts implicitly to
78
+ // an integral type.
79
+ template <typename T>
80
+ struct IsIntEnum {
81
+ private:
82
+ // This overload is used if the type is an enum, and unary plus
83
+ // compiles and turns it into an integral type.
84
+ template <typename X,
85
+ typename std::enable_if<
86
+ std::is_enum<X>::value &&
87
+ std::is_integral<decltype(+std::declval<X>())>::value>::type* =
88
+ nullptr>
89
+ static int Test(int);
90
+
91
+ // Otherwise, this overload is used.
92
+ template <typename>
93
+ static char Test(...);
94
+
95
+ public:
96
+ static constexpr bool value =
97
+ std::is_same<decltype(Test<typename std::remove_reference<T>::type>(0)),
98
+ int>::value;
99
+ };
100
+
101
+ } // namespace type_traits_impl
102
+
103
+ // Determines if the given type is integral, or an enum that
104
+ // converts implicitly to an integral type.
105
+ template <typename T>
106
+ struct IsIntlike {
107
+ private:
108
+ using X = typename std::remove_reference<T>::type;
109
+
110
+ public:
111
+ static constexpr bool value =
112
+ std::is_integral<X>::value || type_traits_impl::IsIntEnum<X>::value;
113
+ };
114
+
115
+ namespace test_enum_intlike {
116
+
117
+ enum E1 { e1 };
118
+ enum { e2 };
119
+ enum class E3 { e3 };
120
+ struct S {};
121
+
122
+ static_assert(type_traits_impl::IsIntEnum<E1>::value, "");
123
+ static_assert(type_traits_impl::IsIntEnum<decltype(e2)>::value, "");
124
+ static_assert(!type_traits_impl::IsIntEnum<E3>::value, "");
125
+ static_assert(!type_traits_impl::IsIntEnum<int>::value, "");
126
+ static_assert(!type_traits_impl::IsIntEnum<float>::value, "");
127
+ static_assert(!type_traits_impl::IsIntEnum<S>::value, "");
128
+
129
+ static_assert(IsIntlike<E1>::value, "");
130
+ static_assert(IsIntlike<decltype(e2)>::value, "");
131
+ static_assert(!IsIntlike<E3>::value, "");
132
+ static_assert(IsIntlike<int>::value, "");
133
+ static_assert(!IsIntlike<float>::value, "");
134
+ static_assert(!IsIntlike<S>::value, "");
135
+
136
+ } // namespace test_enum_intlike
137
+
138
+ } // namespace rtc
139
+
140
+ #endif // RTC_BASE_TYPE_TRAITS_H_