1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/meta/if.h
3 // Purpose:     declares wxIf<> metaprogramming construct
4 // Author:      Vaclav Slavik
5 // Created:     2008-01-22
6 // Copyright:   (c) 2008 Vaclav Slavik
7 // Licence:     wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9 
10 #ifndef _WX_META_IF_H_
11 #define _WX_META_IF_H_
12 
13 #include "wx/defs.h"
14 
15 namespace wxPrivate
16 {
17 
18 template <bool Cond>
19 struct wxIfImpl;
20 
21 // specialization for true:
22 template <>
23 struct wxIfImpl<true>
24 {
25     template<typename TTrue, typename TFalse> struct Result
26     {
27         typedef TTrue value;
28     };
29 };
30 
31 // specialization for false:
32 template<>
33 struct wxIfImpl<false>
34 {
35     template<typename TTrue, typename TFalse> struct Result
36     {
37         typedef TFalse value;
38     };
39 };
40 
41 } // namespace wxPrivate
42 
43 // wxIf<> template defines nested type "value" which is the same as
44 // TTrue if the condition Cond (boolean compile-time constant) was met and
45 // TFalse if it wasn't.
46 //
47 // See wxVector<T> in vector.h for usage example
48 template<bool Cond, typename TTrue, typename TFalse>
49 struct wxIf
50 {
51     typedef typename wxPrivate::wxIfImpl<Cond>
52                      ::template Result<TTrue, TFalse>::value
53             value;
54 };
55 
56 #endif // _WX_META_IF_H_
57