Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. template<class T>
  2. class C
  3. {
  4. void common() { ... }
  5. void f2 = delete;
  6. };
  7.  
  8. template<>
  9. class C<int>
  10. {
  11. void common() { ... }
  12. void f1() { ... }
  13. };
  14.  
  15. template<class T>
  16. class C
  17. {
  18. void common() { ... }
  19.  
  20. static_if(std::is_same<T, int>::value)
  21. {
  22. void f1( ) { ... }
  23. }
  24. else
  25. {
  26. void f2( ) = delete;
  27. }
  28. }
  29.  
  30. struct S {};
  31.  
  32. template<typename T>
  33. struct T
  34. static_if(is_same<T,int>::value) { : S } // ?
  35. { };
  36.  
  37. template<typename T>
  38. struct T {};
  39.  
  40. template<>
  41. struct T<int> : S {};
  42.  
  43. template <typename To, typename From> struct ShapeCaster
  44. {
  45. static To & cast(From & x) { return dynamic_cast<To&>(x); }
  46. };
  47.  
  48. template <> struct ShapeCaster<Triangle, Shape>
  49. {
  50. static Triangle & cast(Shape & x) { return static_cast<Triangle&>(x); }
  51. };
  52.  
  53. template <typename To, typename From> To & shape_cast(From & x)
  54. {
  55. return ShapeCaster<To, From>::cast(x);
  56. }
  57.  
  58. To & y = shape_cast<To>::cast(x);
  59.  
  60. template<typename, typename>
  61. struct is_same{
  62. static constexpr bool value = false;;
  63. };
  64. template<typename T>
  65. struct is_same<T, T>{
  66. static constexpr bool value = true;;
  67. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement