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

memory.hxx
1 /************************************************************************/
2 /* */
3 /* Copyright 2002-2003 by Ullrich Koethe, Hans Meine */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35 
36 #ifndef VIGRA_MEMORY_HXX
37 #define VIGRA_MEMORY_HXX
38 
39 #include "metaprogramming.hxx"
40 
41 namespace vigra {
42 
43 enum SkipInitializationTag { SkipInitialization};
44 
45 template<class T>
46 struct CanSkipInitialization
47 {
48  typedef typename TypeTraits<T>::isBuiltinType type;
49  static const bool value = type::asBool;
50 };
51 
52 namespace detail {
53 
54 template <class T>
55 inline void destroy_n(T * /* p */, std::ptrdiff_t /* n */, VigraTrueType /* isPOD */)
56 {
57 }
58 
59 template <class T>
60 inline void destroy_n(T * p, std::ptrdiff_t n, VigraFalseType /* isPOD */)
61 {
62  T * end = p + n;
63  for(; p != end; ++p)
64  p->~T();
65 }
66 
67 template <class T>
68 inline void destroy_n(T * p, std::ptrdiff_t n)
69 {
70  destroy_n(p, n, typename TypeTraits<T>::isPOD());
71 }
72 
73 /********************************************************************/
74 
75 // g++ 2.95 has std::destroy() in the STL
76 #if !defined(__GNUC__) || __GNUC__ >= 3
77 
78 template <class T>
79 inline void destroy(T * p, VigraTrueType /* isPOD */)
80 {
81 }
82 
83 template <class T>
84 inline void destroy(T * p, VigraFalseType /* isPOD */)
85 {
86  p->~T();
87 }
88 
89 template <class T>
90 inline void destroy(T * p)
91 {
92  destroy(p, typename TypeTraits<T>::isPOD());
93 }
94 
95 #else
96 
97 } } // namespace vigra::detail
98 
99 #include <memory>
100 
101 namespace vigra { namespace detail {
102 
103 using std::destroy;
104 
105 #endif
106 
107 } } // namespace vigra::detail
108 
109 #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.1 (Tue Jul 10 2012)