compilation fix for bcc 5.82: don't use enum for value definition, Borland doesn't use the value correctly when the template is used later then

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51809 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2008-02-15 14:16:32 +00:00
parent fd3fe3ec79
commit 40e01f4bfa

View File

@ -14,6 +14,17 @@
#include "wx/defs.h" #include "wx/defs.h"
#include "wx/string.h" // for wxIsMovable<wxString> specialization #include "wx/string.h" // for wxIsMovable<wxString> specialization
// This macro declares something called "value" inside a class declaration.
//
// It has to be used because VC6 doesn't handle initialization of the static
// variables in the class declaration itself while BCC5.82 doesn't understand
// enums (it compiles the template fine but can't use it later)
#if defined(__VISUALC__) && !wxCHECK_VISUALC_VERSION(7)
#define wxDEFINE_TEMPLATE_BOOL_VALUE(val) enum { value = val }
#else
#define wxDEFINE_TEMPLATE_BOOL_VALUE(val) static const bool value = val
#endif
// Helper to decide if an object of type T is "movable", i.e. if it can be // Helper to decide if an object of type T is "movable", i.e. if it can be
// copied to another memory location using memmove() or realloc() C functions. // copied to another memory location using memmove() or realloc() C functions.
// C++ only gurantees that POD types (including primitive types) are // C++ only gurantees that POD types (including primitive types) are
@ -21,8 +32,7 @@
template<typename T> template<typename T>
struct wxIsMovable struct wxIsMovable
{ {
// NB: enum, because VC6 can't handle "static const bool value = true;" wxDEFINE_TEMPLATE_BOOL_VALUE(false);
enum { value = false };
}; };
// Macro to add wxIsMovable<T> specialization for given type that marks it // Macro to add wxIsMovable<T> specialization for given type that marks it
@ -30,7 +40,7 @@ struct wxIsMovable
#define WX_DECLARE_TYPE_MOVABLE(type) \ #define WX_DECLARE_TYPE_MOVABLE(type) \
template<> struct wxIsMovable<type> \ template<> struct wxIsMovable<type> \
{ \ { \
enum { value = true }; \ wxDEFINE_TEMPLATE_BOOL_VALUE(true); \
}; };
WX_DECLARE_TYPE_MOVABLE(bool) WX_DECLARE_TYPE_MOVABLE(bool)
@ -62,12 +72,13 @@ WX_DECLARE_TYPE_MOVABLE(wxULongLong_t)
template<typename T> template<typename T>
struct wxIsMovable<T*> struct wxIsMovable<T*>
{ {
enum { value = true }; static const bool value = true;
}; };
template<typename T> template<typename T>
struct wxIsMovable<const T*> struct wxIsMovable<const T*>
{ {
enum { value = true }; static const bool value = true;
}; };
#endif // !VC++ < 7 #endif // !VC++ < 7
@ -81,5 +92,4 @@ struct wxIsMovable<const T*>
WX_DECLARE_TYPE_MOVABLE(wxString) WX_DECLARE_TYPE_MOVABLE(wxString)
#endif #endif
#endif // _WX_META_MOVABLE_H_ #endif // _WX_META_MOVABLE_H_