Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "test.h"
- #include "lib-return.h"
- #include <tuple>
- enum class Types
- {
- SUCCESS = 0,
- FAIL
- };
- class Error
- {
- public:
- Error(Types type = Types::SUCCESS) : _type(type) {}
- ~Error(){}
- Types _type;
- operator bool()
- {
- return (_type != Types::SUCCESS);
- }
- };
- template<typename ...T>
- class Result : public Error, public T...
- {
- public:
- };
- //---------------------------------------------| info |---------------------------------------------//
- template<std::size_t N, typename T, typename... types>
- struct get_Nth_type
- {
- using type = typename get_Nth_type<N - 1, types...>::type;
- };
- template<typename T, typename... types>
- struct get_Nth_type<0, T, types...>
- {
- using type = T;
- };
- template<std::size_t N, typename... Args>
- using nth_type = typename get_Nth_type<N, Args...>::type;
- //---------------------------------------------| info |---------------------------------------------//
- template<typename ...T>
- struct std::tuple_size<Result<T...>>
- {
- static const std::size_t value = sizeof...(T) + 1;
- };
- template<std::size_t I, typename ...T>
- struct std::tuple_element<I, Result<T...>>
- {
- //using type = typename std::tuple_element<I, std::tuple<Error, T...> >::type;
- using type = nth_type<I, Error, T...>;
- };
- template<std::size_t I, typename ...T>
- nth_type<I, Error, T...> get(Result<T...> t)
- {
- //return (*(typename std::tuple_element<I, std::tuple<Error, T...>>::type *)(&t));
- return *((nth_type<I, Error, T...> *)(&t));
- }
- struct Time_load
- {
- int k;
- };
- struct t2
- {
- char as;
- };
- Result<Time_load, t2> f()
- {
- Result<Time_load, t2> temp;
- temp.as = 2;
- temp.k = 2;
- temp._type = Types::FAIL;
- return temp;
- }
- #define check(X) if (X) return X
- Error ssdda()
- {
- auto [error, time_load, as] = f();
- check(error);
- return Types::FAIL;
- }
- TEST_CASE("t1")
- {
- auto result = ssdda();
- int l2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement