Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include "test.h"
  2. #include "lib-return.h"
  3. #include <tuple>
  4.  
  5. enum class Types
  6. {
  7. SUCCESS = 0,
  8. FAIL
  9. };
  10.  
  11. class Error
  12. {
  13. public:
  14. Error(Types type = Types::SUCCESS) : _type(type) {}
  15. ~Error(){}
  16.  
  17. Types _type;
  18.  
  19. operator bool()
  20. {
  21. return (_type != Types::SUCCESS);
  22. }
  23. };
  24.  
  25. template<typename ...T>
  26. class Result : public T...
  27. {
  28. public:
  29. Error error;
  30.  
  31. };
  32.  
  33. //---------------------------------------------| info |---------------------------------------------//
  34.  
  35. template<std::size_t N, typename T, typename... types>
  36. struct get_Nth_type
  37. {
  38. using type = typename get_Nth_type<N - 1, types...>::type;
  39. };
  40.  
  41. template<typename T, typename... types>
  42. struct get_Nth_type<0, T, types...>
  43. {
  44. using type = T;
  45. };
  46.  
  47. template<std::size_t N, typename... Args>
  48. using nth_type = typename get_Nth_type<N, Args...>::type;
  49.  
  50. //---------------------------------------------| info |---------------------------------------------//
  51.  
  52. template<typename ...T>
  53. struct std::tuple_size<Result<T...>>
  54. {
  55. static const std::size_t value = sizeof...(T) + 1;
  56. };
  57.  
  58. template<std::size_t I, typename ...T>
  59. struct std::tuple_element<I, Result<T...>>
  60. {
  61. //using type = typename std::tuple_element<I, std::tuple<Error, T...> >::type;
  62.  
  63. using type = nth_type<I, Error, T...>;
  64. };
  65.  
  66. template<std::size_t I, typename ...T>
  67. nth_type<I, Error, T...> get(Result<T...> t)
  68. {
  69. //return (*(typename std::tuple_element<I, std::tuple<Error, T...>>::type *)(&t));
  70.  
  71. return *((nth_type<I, Error, T...> *)(&t));
  72. }
  73.  
  74. struct Time_load
  75. {
  76. int k;
  77. };
  78.  
  79. struct t2
  80. {
  81. char as;
  82. };
  83.  
  84. Result<Time_load, t2> f()
  85. {
  86. Result<Time_load, t2> temp;
  87.  
  88. temp.as = 2;
  89. temp.k = 2;
  90. temp.error = Types::FAIL;
  91.  
  92. return temp;
  93. }
  94.  
  95. #define check(X) if (X) return X
  96.  
  97. Error ssdda()
  98. {
  99. auto [error, time_load, as] = f();
  100. check(error);
  101.  
  102. return Types::FAIL;
  103. }
  104.  
  105. template<typename ...T>
  106. void ma()
  107. {
  108. nth_type<0, Error, T...> test;
  109. }
  110.  
  111. TEST_CASE("t1")
  112. {
  113. ma<int, char>();
  114.  
  115. int l2;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement