# gdcmStaticAssert.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2010 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015 #ifndef GDCMSTATICASSERT_H
    00016 #define GDCMSTATICASSERT_H
    00017
    00018
    00019 // the following was shamelessly borowed from BOOST static assert:
    00020 namespace gdcm
    00021 {
    00022   template <bool x>
    00023   struct STATIC_ASSERTION_FAILURE;
    00024
    00025   template <>
    00026   struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
    00027
    00028   template <int x>
    00029   struct static_assert_test {};
    00030 }
    00031
    00032 #define GDCM_JOIN( X, Y ) GDCM_DO_JOIN( X, Y )
    00033 #define GDCM_DO_JOIN( X, Y ) GDCM_DO_JOIN2(X,Y)
    00034 #define GDCM_DO_JOIN2( X, Y ) X##Y
    00035
    00037 #define GDCM_STATIC_ASSERT( B ) \
    00038   typedef ::gdcm::static_assert_test<\
    00039     sizeof(::gdcm::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
    00040       GDCM_JOIN(gdcm_static_assert_typedef_, __LINE__)
    00041
    00042
    00043 /* Example of use:
    00044  *
    00045  * template <class T>
    00046  * struct must_not_be_instantiated
    00047  * {
    00048  * // this will be triggered if this type is instantiated
    00049  * GDCM_STATIC_ASSERT(sizeof(T) == 0);
    00050  * };
    00051  *
    00052  */
    00053 #endif // GDCMSTATICASSERT_H