1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef WW_STATICASSERT_HXX 25 #define WW_STATICASSERT_HXX 26 27 /* 28 Lifted direct from: 29 Modern C++ Design: Generic Programming and Design Patterns Applied 30 Section 2.1 31 by Andrei Alexandrescu 32 */ 33 namespace ww 34 { 35 template<bool> class compile_time_check 36 { 37 public: compile_time_check(...)38 compile_time_check(...) {} 39 }; 40 41 template<> class compile_time_check<false> 42 { 43 }; 44 } 45 46 /* 47 Similar to assert, StaticAssert is only in operation when NDEBUG is not 48 defined. It will test its first argument at compile time and on failure 49 report the error message of the second argument, which must be a valid c++ 50 classname. i.e. no spaces, punctuation or reserved keywords. 51 */ 52 #ifndef NDEBUG 53 # define StaticAssert(test, errormsg) \ 54 do { \ 55 struct ERROR_##errormsg {}; \ 56 typedef ww::compile_time_check< (test) != 0 > tmplimpl; \ 57 tmplimpl aTemp = tmplimpl(ERROR_##errormsg()); \ 58 sizeof(aTemp); \ 59 } while (0) 60 #else 61 # define StaticAssert(test, errormsg) \ 62 do {} while (0) 63 #endif 64 65 #endif 66 67 /* vim: set noet sw=4 ts=4: */ 68