#include <NCollection_StdAllocator.hxx>
#include <NCollection_IncAllocator.hxx>
+#include <Standard_Assert.hxx>
+
#include <list>
#include <vector>
//type definitions
typedef Handle_Standard_Transient elem_type;
typedef NCollection_StdAllocator<elem_type> allocator_type;
- if ( sizeof (allocator_type::value_type) == sizeof (elem_type) ) {
- di << "value_type : OK\n";
- } else {
- di << "value_type : Error\n";
- }
- if ( sizeof (allocator_type::pointer) == sizeof (void*) ) {
- di << "pointer : OK\n";
- } else {
- di << "pointer : Error\n";
- }
- if (sizeof (allocator_type::const_pointer) == sizeof (void*) ) {
- di << "const_pointer : OK\n";
- } else {
- di << "const_pointer : Error\n";
- }
+ Standard_STATIC_ASSERT (sizeof (allocator_type::value_type) == sizeof (elem_type));
+ Standard_STATIC_ASSERT (sizeof (allocator_type::pointer) == sizeof (void*));
+ Standard_STATIC_ASSERT (sizeof (allocator_type::const_pointer) == sizeof (void*));
elem_type aDummy;
allocator_type::reference aRef = aDummy;
(void)aRef; // avoid compiler warning on unused
allocator_type::const_reference aConstRef = aDummy;
(void)aConstRef; // avoid compiler warning on unused
- if ( sizeof (allocator_type::size_type) == sizeof (size_t) ) {
- di << "size_type : OK\n";
- } else {
- di << "size_type : Error\n";
- }
- if ( sizeof (allocator_type::difference_type) == sizeof (ptrdiff_t) ) {
- di << "allocator_type : OK\n";
- } else {
- di << "allocator_type : Error\n";
- }
+ Standard_STATIC_ASSERT (sizeof (allocator_type::size_type) == sizeof (size_t));
+ Standard_STATIC_ASSERT (sizeof (allocator_type::difference_type) == sizeof (ptrdiff_t));
typedef int other_elem_type;
- if ( sizeof (allocator_type::rebind<other_elem_type>::other::value_type) == sizeof (other_elem_type) ) {
- di << "other_elem_type : OK\n";
- } else {
- di << "other_elem_type : Error\n";
- }
+ Standard_STATIC_ASSERT (sizeof (allocator_type::rebind<other_elem_type>::other::value_type) == sizeof (other_elem_type));
return 0;
}
//!
//! The second argument (message) should be string constant ("...").
//!
+//! The Standard_STATIC_ASSERT macro is to be used for compile time checks.
+//! To use this macro, write:
+//!
+//! Standard_STATIC_ASSERT(const_expression);
+//!
+//! If const_expression is false, a compiler error occurs.
+//!
//! The macros are formed as functions and require semicolon at the end.
// Stub function used to make macros complete C++ operator
//! Raise debug message
#define Standard_ASSERT_INVOKE(theDesc) Standard_ASSERT_INVOKE_(always, theDesc)
+//! Static assert --
+//! empty default template
+template <bool condition>
+struct Standard_Static_Assert { };
+
+//! Static assert -- specialization for condition being true
+template <>
+struct Standard_Static_Assert<true>
+{
+ static void assert_ok() {}
+};
+
+//! Cause compiler error if argument is not constant expression or
+//! evaluates to false
+#define Standard_STATIC_ASSERT(theExpr) \
+ Standard_Static_Assert<theExpr>::assert_ok();
+
#endif // Standard_Assert_HeaderFile
#ifdef _MSC_VER
#include <Standard_MMgrOpt.hxx>
#include <Standard_OutOfMemory.hxx>
-
+#include <Standard_Assert.hxx>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
const Standard_Size aThreshold)
{
// check basic assumption
- if ( sizeof(Standard_Size) != sizeof(Standard_Address) )
- {
- cerr << "Fatal error: Open CASCADE Optimized Memory manager: this platform is not supported!" << endl;
- exit(1);
- }
+ Standard_STATIC_ASSERT(sizeof(Standard_Size) == sizeof(Standard_Address));
// clear buffer fields
myFreeListMax = 0;