Skip to content

Commit 1714f6c

Browse files
authored
[src] Use 'static_assert' for KALDI_COMPILE_TIME_ASSERT (#4566)
Remove 'template<bool B> class KaldiCompileTimeAssert' because 'static_assert' is now a language declaration. Before C++17 a second argument for the message is required (lame, lame!), which is, lacking anything better, is obtained by stringizing the function-like macro argument. For C++17, the second argument is optional, and the semantics of 'KALDI_COMPILE_TIME_ASSERT' and 'static_assert' is identical when the second argument to the latter is not provided.
1 parent 8184005 commit 1714f6c

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/base/kaldi-utils.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,19 @@ void Sleep(double seconds);
131131
type(const type&) = delete; \
132132
type& operator=(const type&) = delete
133133

134-
template<bool B> class KaldiCompileTimeAssert { };
135-
template<> class KaldiCompileTimeAssert<true> {
136-
public:
137-
static inline void Check() { }
138-
};
139-
140-
#define KALDI_COMPILE_TIME_ASSERT(b) KaldiCompileTimeAssert<(b)>::Check()
134+
#if __cplusplus >= 201703L
135+
#define KALDI_COMPILE_TIME_ASSERT static_assert
136+
#else
137+
#define KALDI_COMPILE_TIME_ASSERT(b) static_assert((b), #b)
138+
#endif
141139

142140
#define KALDI_ASSERT_IS_INTEGER_TYPE(I) \
143-
KaldiCompileTimeAssert<std::numeric_limits<I>::is_specialized \
144-
&& std::numeric_limits<I>::is_integer>::Check()
141+
KALDI_COMPILE_TIME_ASSERT(std::numeric_limits<I>::is_specialized \
142+
&& std::numeric_limits<I>::is_integer)
145143

146144
#define KALDI_ASSERT_IS_FLOATING_TYPE(F) \
147-
KaldiCompileTimeAssert<std::numeric_limits<F>::is_specialized \
148-
&& !std::numeric_limits<F>::is_integer>::Check()
145+
KALDI_COMPILE_TIME_ASSERT(std::numeric_limits<F>::is_specialized \
146+
&& !std::numeric_limits<F>::is_integer)
149147

150148
#if defined(_MSC_VER)
151149
#define KALDI_STRCASECMP _stricmp

0 commit comments

Comments
 (0)