I am reading the machine learning library dlib which is written in C++. I came across a code in a header file which defines a bunch of macros. I have difficulties understanding the following code
#ifndef BOOST_JOIN
#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
#define BOOST_DO_JOIN2( X, Y ) X##Y
#endif
// a bunch of other code
namespace dlib
{
template <bool value> struct compile_time_assert;
template <> struct compile_time_assert<true> { enum {value=1}; };
// a bunch of other definitions
}
#define COMPILE_TIME_ASSERT(expression) \
DLIB_NO_WARN_UNUSED typedef char BOOST_JOIN(DLIB_CTA, __LINE__)[::dlib::compile_time_assert<(bool)(expression)>::value]
what I do not understand is that
what does the last line in the above code do?
typedef char
here is so weird, I don't understand it at all.- After substitution for
BOOST_JOIN
, it becomesDLIB_CTA__LINE__[1]
, why it is an array? Is it legal?