/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ #ifndef WW_STATICASSERT_HXX #define WW_STATICASSERT_HXX /* Lifted direct from: Modern C++ Design: Generic Programming and Design Patterns Applied Section 2.1 by Andrei Alexandrescu */ namespace ww { template class compile_time_check { public: compile_time_check(...) {} }; template<> class compile_time_check { }; } /* Similiar to assert, StaticAssert is only in operation when NDEBUG is not defined. It will test its first argument at compile time and on failure report the error message of the second argument, which must be a valid c++ classname. i.e. no spaces, punctuation or reserved keywords. */ #ifndef NDEBUG # define StaticAssert(test, errormsg) \ do { \ struct ERROR_##errormsg {}; \ typedef ww::compile_time_check< (test) != 0 > tmplimpl; \ tmplimpl aTemp = tmplimpl(ERROR_##errormsg()); \ sizeof(aTemp); \ } while (0) #else # define StaticAssert(test, errormsg) \ do {} while (0) #endif #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */