Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Index: is-a.h
  2. ===================================================================
  3. --- is-a.h (revision 217985)
  4. +++ is-a.h (working copy)
  5. @@ -147,10 +147,26 @@ struct is_a_helper
  6. {
  7. template <typename U>
  8. static inline bool test (U *p);
  9. + static inline bool test (T *) { return true; }
  10. template <typename U>
  11. static inline T cast (U *p);
  12. };
  13.  
  14. +
  15. +template <typename T>
  16. +struct is_a_helper<const T*>
  17. +{
  18. + template <typename U>
  19. + static inline bool test (const U *p);
  20. + template <typename U>
  21. + static inline bool test (U *p) {return test(const_cast<const U*>(p));}
  22. + static inline bool test (const T *) { return true; }
  23. + template <typename U>
  24. + static inline const T *cast (const U *p);
  25. + template <typename U>
  26. + static inline const T *cast (U *p) { return cast(const_cast<const U*>(p)); }
  27. +};
  28. +
  29. /* Note that we deliberately do not define the 'test' member template. Not
  30. doing so will result in a build-time error for type relationships that have
  31. not been defined, rather than a run-time error. See the discussion above
  32. @@ -169,6 +185,15 @@ is_a_helper <T>::cast (U *p)
  33. }
  34.  
  35.  
  36. +template <typename T>
  37. +template <typename U>
  38. +inline const T*
  39. +is_a_helper <const T*>::cast (const U *p)
  40. +{
  41. + return reinterpret_cast <const T*> (p);
  42. +}
  43. +
  44. +
  45. /* The public interface. */
  46.  
  47. /* A generic test for a type relationship. See the discussion above for when
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement