Update ooo320-m1
[ooovba.git] / sw / source / filter / ww8 / staticassert.hxx
blob586ad18a359a4387f374c3e0c59ceafbf9d8d6bd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: staticassert.hxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
32 #ifndef WW_STATICASSERT_HXX
33 #define WW_STATICASSERT_HXX
36 Lifted direct from:
37 Modern C++ Design: Generic Programming and Design Patterns Applied
38 Section 2.1
39 by Andrei Alexandrescu
41 namespace ww
43 template<bool> class compile_time_check
45 public:
46 compile_time_check(...) {}
49 template<> class compile_time_check<false>
55 Similiar to assert, StaticAssert is only in operation when NDEBUG is not
56 defined. It will test its first argument at compile time and on failure
57 report the error message of the second argument, which must be a valid c++
58 classname. i.e. no spaces, punctuation or reserved keywords.
60 #ifndef NDEBUG
61 # define StaticAssert(test, errormsg) \
62 do { \
63 struct ERROR_##errormsg {}; \
64 typedef ww::compile_time_check< (test) != 0 > tmplimpl; \
65 tmplimpl aTemp = tmplimpl(ERROR_##errormsg()); \
66 sizeof(aTemp); \
67 } while (0)
68 #else
69 # define StaticAssert(test, errormsg) \
70 do {} while (0)
71 #endif
73 #endif
74 /* vi:set tabstop=4 shiftwidth=4 expandtab: */