mirror of https://github.com/davisking/dlib.git
Added a macro to assert on a type being a POD or a standard layout type.
This way I can change just this one macro to use the better C++0x method of doing this check once C++0x becomes available.
This commit is contained in:
parent
ecfa04941d
commit
3b9fbda0e1
19
dlib/algs.h
19
dlib/algs.h
|
@ -931,6 +931,25 @@ namespace dlib
|
||||||
void* const data;
|
void* const data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*A DLIB_ASSERT_HAS_STANDARD_LAYOUT
|
||||||
|
|
||||||
|
This macro is meant to cause a compiler error if a type doesn't have a simple
|
||||||
|
memory layout (like a C struct). In particular, types with simple layouts are
|
||||||
|
ones which can be copied via memcpy().
|
||||||
|
|
||||||
|
|
||||||
|
This was called a POD type in C++03 and in C++0x we are looking to check if
|
||||||
|
it is a "standard layout type". Once we can use C++0x we can change this macro
|
||||||
|
to something that uses the std::is_standard_layout type_traits class.
|
||||||
|
See: http://www2.research.att.com/~bs/C++0xFAQ.html#PODs
|
||||||
|
*/
|
||||||
|
// Use the fact that in C++03 you can't put non-PODs into a union.
|
||||||
|
#define DLIB_ASSERT_HAS_STANDARD_LAYOUT(type) \
|
||||||
|
union BOOST_JOIN(DAHSL_,__LINE__) { type TYPE_NOT_STANDARD_LAYOUT; }; \
|
||||||
|
typedef char BOOST_JOIN(DAHSL2_,__LINE__)[sizeof(BOOST_JOIN(DAHSL_,__LINE__))];
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue