type_traits.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ZORBA_INTERNAL_TYPE_TRAITS_H
18 #define ZORBA_INTERNAL_TYPE_TRAITS_H
19 
20 #include <zorba/config.h>
21 
22 #ifdef ZORBA_TR1_IN_TR1_SUBDIRECTORY
23 # include <tr1/type_traits>
24 #else
25 # include <type_traits>
26 #endif
27 
28 ///////////////////////////////////////////////////////////////////////////////
29 
30 #ifndef ZORBA_HAVE_ENABLE_IF
31 namespace std {
32 
33 /**
34  * \internal
35  * Define our own version of \c enable_if since g++ 4.2.1 (the version that
36  * comes with Xcode 3.x) doesn't have \c enable_if.
37  */
38 template<bool,typename T = void>
39 struct enable_if {
40 };
41 
42 /**
43  * \internal
44  * Specialization of \c enable_if for the \c true case.
45  */
46 template<typename T>
47 struct enable_if<true,T> {
48  typedef T type;
49 };
50 
51 } // namespace std
52 #endif /* ZORBA_HAVE_ENABLE_IF */
53 
54 ///////////////////////////////////////////////////////////////////////////////
55 
56 #ifndef ZORBA_HAVE_UNIQUE_PTR
57 namespace zorba {
58 namespace internal {
59 
60 /**
61  * \internal
62  * Dummy rvalue class used by unique_ptr to prevent implicit copying.
63  */
64 template<typename T>
65 class rv : public T {
66  rv();
67  ~rv();
68  rv( rv const& );
69  rv& operator=( rv const& );
70  //
71  // The struct and friend declaration below eliminate a "class rv<T> only
72  // defines a private destructor and has no friends" warning.
73  //
74  struct f;
75  friend struct f;
76 };
77 
78 template<bool B>
79 struct bool_value {
80  static bool const value = B;
81 };
82 
83 template<typename T>
84 struct is_movable : bool_value<ZORBA_TR1_NS::is_convertible<T,rv<T>&>::value> {
85 };
86 
87 template<typename T>
88 struct is_movable< rv<T> > : bool_value<false> {
89 };
90 
91 } // namespace internal
92 } // namespace zorba
93 #endif /* ZORBA_HAVE_UNIQUE_PTR */
94 
95 ///////////////////////////////////////////////////////////////////////////////
96 
97 #endif /* ZORBA_INTERNAL_TYPE_TRAITS_H */
98 /* vim:set et sw=2 ts=2: */