[ 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 // differs from std::uninitialized_copy by explicit type conversion
55 template <class Src, class Dest>
56 Dest uninitializedCopy(Src s, Src end, Dest d)
57 {
58 typedef typename std::iterator_traits<Dest>::value_type T;
59 for(; s != end; ++s, ++d)
60 new(d) T(static_cast<T const &>(*s));
61 return d;
62 }
63
64 template <class T>
65 inline void destroy_n(T * /* p */, std::ptrdiff_t /* n */, VigraTrueType /* isPOD */)
66 {
67 }
68
69 template <class T>
70 inline void destroy_n(T * p, std::ptrdiff_t n, VigraFalseType /* isPOD */)
71 {
72 T * end = p + n;
73 for(; p != end; ++p)
74 p->~T();
75 }
76
77 template <class T>
78 inline void destroy_n(T * p, std::ptrdiff_t n)
79 {
80 destroy_n(p, n, typename TypeTraits<T>::isPOD());
81 }
82
83 /********************************************************************/
84
85 // g++ 2.95 has std::destroy() in the STL
86 #if !defined(__GNUC__) || __GNUC__ >= 3
87
88 template <class T>
89 inline void destroy(T * p, VigraTrueType /* isPOD */)
90 {
91 }
92
93 template <class T>
94 inline void destroy(T * p, VigraFalseType /* isPOD */)
95 {
96 p->~T();
97 }
98
99 template <class T>
100 inline void destroy(T * p)
101 {
102 destroy(p, typename TypeTraits<T>::isPOD());
103 }
104
105 #else
106
107 } } // namespace vigra::detail
108
109 #include <memory>
110
111 namespace vigra { namespace detail {
112
113 using std::destroy;
114
115 #endif
116
117 } } // namespace vigra::detail
118
119 #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.10.0 (Mon Nov 18 2013)