static_check.h

 1 ////////////////////////////////////////////////////////////////////////////////
 2 // The Loki Library
 3 // Copyright (c) 2001 by Andrei Alexandrescu
 4 // This code accompanies the book:
 5 // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design 
 6 //     Patterns Applied". Copyright (c) 2001. Addison-Wesley.
 7 // Permission to use, copy, modify, distribute and sell this software for any 
 8 //     purpose is hereby granted without fee, provided that the above copyright 
 9 //     notice appear in all copies and that both that copyright notice and this 
10 //     permission notice appear in supporting documentation.
11 // The author or Addison-Welsey Longman make no representations about the 
12 //     suitability of this software for any purpose. It is provided "as is" 
13 //     without express or implied warranty.
14 ////////////////////////////////////////////////////////////////////////////////
15 
16 // Last update: June 20, 2001
17 
18 #ifndef STATIC_CHECK_INC_
19 #define STATIC_CHECK_INC_
20 
21 namespace Loki
22 {
23 ////////////////////////////////////////////////////////////////////////////////
24 // Helper structure for the STATIC_CHECK macro
25 ////////////////////////////////////////////////////////////////////////////////
26 
27     template<int> struct CompileTimeError;
28     template<> struct CompileTimeError<true> {};
29 }
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 // macro STATIC_CHECK
33 // Invocation: STATIC_CHECK(expr, id)
34 // where:
35 // expr is a compile-time integral or pointer expression
36 // id is a C++ identifier that does not need to be defined
37 // If expr is zero, id will appear in a compile-time error message.
38 ////////////////////////////////////////////////////////////////////////////////
39 
40 #define STATIC_CHECK(expr, msg) \
41     { Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; } 
42 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 // Change log:
46 // March 20, 2001: add extra parens to STATIC_CHECK - it looked like a fun 
47 //     definition
48 // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
49 ////////////////////////////////////////////////////////////////////////////////
50 
51 #endif // STATIC_CHECK_INC_
posted @ 2012-10-31 15:22  crazylhf  阅读(180)  评论(0)    收藏  举报