[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

vigra/memory.hxx
00001 /************************************************************************/
00002 /*                                                                      */
00003 /*         Copyright 2002-2003 by Ullrich Koethe, Hans Meine            */
00004 /*                                                                      */
00005 /*    This file is part of the VIGRA computer vision library.           */
00006 /*    The VIGRA Website is                                              */
00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
00008 /*    Please direct questions, bug reports, and contributions to        */
00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
00010 /*        vigra@informatik.uni-hamburg.de                               */
00011 /*                                                                      */
00012 /*    Permission is hereby granted, free of charge, to any person       */
00013 /*    obtaining a copy of this software and associated documentation    */
00014 /*    files (the "Software"), to deal in the Software without           */
00015 /*    restriction, including without limitation the rights to use,      */
00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
00017 /*    sell copies of the Software, and to permit persons to whom the    */
00018 /*    Software is furnished to do so, subject to the following          */
00019 /*    conditions:                                                       */
00020 /*                                                                      */
00021 /*    The above copyright notice and this permission notice shall be    */
00022 /*    included in all copies or substantial portions of the             */
00023 /*    Software.                                                         */
00024 /*                                                                      */
00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */                
00033 /*                                                                      */
00034 /************************************************************************/
00035 
00036 #ifndef VIGRA_MEMORY_HXX
00037 #define VIGRA_MEMORY_HXX
00038 
00039 #include "metaprogramming.hxx"
00040 
00041 namespace vigra { 
00042 
00043 enum SkipInitializationTag { SkipInitialization};
00044 
00045 template<class T>
00046 struct CanSkipInitialization
00047 {
00048     typedef typename TypeTraits<T>::isBuiltinType type;
00049     static const bool value = type::asBool;
00050 };
00051 
00052 namespace detail {
00053 
00054 template <class T>
00055 inline void destroy_n(T * /* p */, std::ptrdiff_t /* n */, VigraTrueType /* isPOD */)
00056 {
00057 }
00058 
00059 template <class T>
00060 inline void destroy_n(T * p, std::ptrdiff_t n, VigraFalseType /* isPOD */)
00061 {
00062     T * end = p + n;
00063     for(; p != end; ++p)
00064         p->~T();
00065 }
00066 
00067 template <class T>
00068 inline void destroy_n(T * p, std::ptrdiff_t n)
00069 {
00070     destroy_n(p, n, typename TypeTraits<T>::isPOD());
00071 }
00072 
00073 /********************************************************************/
00074 
00075 // g++ 2.95 has std::destroy() in the STL
00076 #if !defined(__GNUC__) ||  __GNUC__ >= 3
00077 
00078 template <class T>
00079 inline void destroy(T * p, VigraTrueType /* isPOD */)
00080 {
00081 }
00082 
00083 template <class T>
00084 inline void destroy(T * p, VigraFalseType /* isPOD */)
00085 {
00086     p->~T();
00087 }
00088 
00089 template <class T>
00090 inline void destroy(T * p)
00091 {
00092     destroy(p, typename TypeTraits<T>::isPOD());
00093 }
00094 
00095 #else
00096 
00097 } } // namespace vigra::detail
00098 
00099 #include <memory>
00100 
00101 namespace vigra { namespace detail {
00102 
00103 using std::destroy;
00104 
00105 #endif
00106 
00107 } } // namespace vigra::detail
00108 
00109 #endif // VIGRA_MEMORY_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.7.0 (Thu Aug 25 2011)