convertible.h 1022 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/meta/convertible.h
  3. // Purpose: Test if types are convertible
  4. // Author: Arne Steinarson
  5. // Created: 2008-01-10
  6. // Copyright: (c) 2008 Arne Steinarson
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_META_CONVERTIBLE_H_
  10. #define _WX_META_CONVERTIBLE_H_
  11. //
  12. // Introduce an extra class to make this header compilable with g++3.2
  13. //
  14. template <class D, class B>
  15. struct wxConvertibleTo_SizeHelper
  16. {
  17. static char Match(B* pb);
  18. static int Match(...);
  19. };
  20. // Helper to decide if an object of type D is convertible to type B (the test
  21. // succeeds in particular when D derives from B)
  22. template <class D, class B>
  23. struct wxConvertibleTo
  24. {
  25. enum
  26. {
  27. value =
  28. sizeof(wxConvertibleTo_SizeHelper<D,B>::Match(static_cast<D*>(NULL)))
  29. ==
  30. sizeof(char)
  31. };
  32. };
  33. #endif // _WX_META_CONVERTIBLE_H_