StaticAssert.h

Go to the documentation of this file.
00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00030 #ifdef _MSC_VER
00031 #pragma once
00032 #endif  // _MSC_VER
00033 
00034 #ifndef _EXMAT_STATICASSERT_H
00035 #define _EXMAT_STATICASSERT_H
00036 
00037 #include "loki/static_check.h"
00038 
00039 namespace exmat {
00040 
00041 #ifdef EXMAT_GNUC
00042 /************************************************/
00043 // Compile time Assertion
00044 template<bool> struct CompileTimeChecker {
00045     CompileTimeChecker(...);
00046 };
00047 template<> struct CompileTimeChecker<false> {};
00048 #define StaticAssert(expr, msg) \
00049     struct ERROR_##msg { ERROR_##msg(){}; };    \
00050     (void)sizeof(CompileTimeChecker<((expr) != 0)>(ERROR_##msg()))
00051 
00052 template<class chk> struct ERROR_dummy{};
00053 // StaticAssert1 can be used anywhere, including class definition
00054 #define StaticAssert1(expr, msg)    \
00055     struct ERROR_##msg { ERROR_##msg(){}; };    \
00056     typedef ERROR_dummy<CompileTimeChecker<((expr) != 0)>(ERROR_##msg())> DummyTypedef;
00057 
00058 };
00059 #else
00060 
00061 template<bool> struct CompileTimeChecker {
00062     CompileTimeChecker(...);
00063 };
00065 template<> struct CompileTimeChecker<false> {};
00066 #define StaticAssert(expr, msg) \
00067     struct ERROR_##msg { ERROR_##msg(){}; };    \
00068     (void)sizeof(CompileTimeChecker<((expr) != 0)>(ERROR_##msg()))
00069 
00070 template<int chk> struct ERROR_dummy{};
00071 // StaticAssert1 can be used anywhere, including class definition
00072 #define StaticAssert1(expr, msg)    \
00073     struct ERROR_##msg { ERROR_##msg(){}; };    \
00074     typedef ERROR_dummy<sizeof(CompileTimeChecker<((expr) != 0)>(ERROR_##msg()))> DummyTypedef;
00075 
00076 };
00077 #endif
00078 
00079 #endif  // _EXMAT_STATICASSERT_H

Generated on Sat May 6 23:12:01 2006 for Exmat by  doxygen 1.4.6-NO