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