]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/meta/movable.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/meta/movable.h
3 // Purpose: Test if a type is movable using memmove() etc.
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2008 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_META_MOVABLE_H_
12 #define _WX_META_MOVABLE_H_
15 #include "wx/string.h" // for wxIsMovable<wxString> specialization
17 // Helper to decide if an object of type T is "movable", i.e. if it can be
18 // copied to another memory location using memmove() or realloc() C functions.
19 // C++ only gurantees that POD types (including primitive types) are
24 // NB: enum, because VC6 can't handle "static const bool value = true;"
25 enum { value
= false };
28 // Macro to add wxIsMovable<T> specialization for given type that marks it
30 #define WX_DECLARE_TYPE_MOVABLE(type) \
31 template<> struct wxIsMovable<type> \
33 enum { value = true }; \
36 WX_DECLARE_TYPE_MOVABLE(bool)
37 WX_DECLARE_TYPE_MOVABLE(unsigned char)
38 WX_DECLARE_TYPE_MOVABLE(signed char)
39 WX_DECLARE_TYPE_MOVABLE(unsigned int)
40 WX_DECLARE_TYPE_MOVABLE(signed int)
41 WX_DECLARE_TYPE_MOVABLE(unsigned short int)
42 WX_DECLARE_TYPE_MOVABLE(signed short int)
43 WX_DECLARE_TYPE_MOVABLE(signed long int)
44 WX_DECLARE_TYPE_MOVABLE(unsigned long int)
45 WX_DECLARE_TYPE_MOVABLE(float)
46 WX_DECLARE_TYPE_MOVABLE(double)
47 WX_DECLARE_TYPE_MOVABLE(long double)
48 #if wxWCHAR_T_IS_REAL_TYPE
49 WX_DECLARE_TYPE_MOVABLE(wchar_t)
52 WX_DECLARE_TYPE_MOVABLE(wxLongLong_t
)
53 WX_DECLARE_TYPE_MOVABLE(wxULongLong_t
)
56 // Visual C++ 6.0 can't compile partial template specializations and as this is
57 // only an optimization, we can live with pointers not being recognized as
58 // movable types under VC6
59 #if !wxCHECK_VISUALC_VERSION(7)
61 // pointers are movable:
63 struct wxIsMovable
<T
*>
65 enum { value
= true };
68 struct wxIsMovable
<const T
*>
70 enum { value
= true };
75 // Our implementation of wxString is written in such way that it's safe to move
76 // it around. OTOH, we don't know anything about std::string.
77 // (NB: we don't put this into string.h and choose to include wx/string.h from
78 // here instead so that rarely-used wxIsMovable<T> code isn't included by
81 WX_DECLARE_TYPE_MOVABLE(wxString
)
85 #endif // _WX_META_MOVABLE_H_