Advertisement
Guest User

Untitled

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