type_traits.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef ZORBA_INTERNAL_TYPE_TRAITS_H
00018 #define ZORBA_INTERNAL_TYPE_TRAITS_H
00019 
00020 #include <zorba/config.h>
00021 
00022 #ifdef ZORBA_TR1_IN_TR1_SUBDIRECTORY
00023 # include <tr1/type_traits>
00024 #else
00025 # include <type_traits>
00026 #endif
00027 
00028 ///////////////////////////////////////////////////////////////////////////////
00029 
00030 #ifndef ZORBA_CXX_ENABLE_IF
00031 namespace std {
00032 
00033 /**
00034  * \internal
00035  * Define our own version of \c enable_if since g++ 4.2.1 (the version that
00036  * comes with Xcode 3.x) doesn't have \c enable_if.
00037  */
00038 template<bool,typename T = void>
00039 struct enable_if {
00040 };
00041 
00042 /**
00043  * \internal
00044  * Specialization of \c enable_if for the \c true case.
00045  */
00046 template<typename T>
00047 struct enable_if<true,T> {
00048   typedef T type;
00049 };
00050 
00051 } // namespace std
00052 #endif /* ZORBA_CXX_ENABLE_IF */
00053 
00054 ///////////////////////////////////////////////////////////////////////////////
00055 
00056 #ifndef ZORBA_CXX_UNIQUE_PTR
00057 namespace zorba {
00058 namespace internal {
00059 
00060 /**
00061  * \internal
00062  * Dummy rvalue class used by unique_ptr to prevent implicit copying.
00063  */
00064 template<typename T>
00065 class rv : public T {
00066   rv();
00067   ~rv();
00068   rv( rv const& );
00069   rv& operator=( rv const& );
00070   //
00071   // The struct and friend declaration below eliminate a "class rv<T> only
00072   // defines a private destructor and has no friends" warning.
00073   //
00074   struct f;
00075   friend struct f;
00076 };
00077 
00078 template<bool B>
00079 struct bool_value {
00080   static bool const value = B;
00081 };
00082 
00083 template<typename T>
00084 struct is_movable : bool_value<ZORBA_TR1_NS::is_convertible<T,rv<T>&>::value> {
00085 };
00086 
00087 template<typename T>
00088 struct is_movable< rv<T> > : bool_value<false> {
00089 };
00090 
00091 } // namespace internal
00092 } // namespace zorba
00093 #endif /* ZORBA_CXX_UNIQUE_PTR */
00094 
00095 ///////////////////////////////////////////////////////////////////////////////
00096 
00097 #endif /* ZORBA_INTERNAL_TYPE_TRAITS_H */
00098 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus