mirror of
https://github.com/Naios/continuable.git
synced 2026-02-15 22:59:49 +08:00
reorganize forward declarations
This commit is contained in:
parent
9452121cae
commit
47e23e9719
@ -36,7 +36,6 @@ void debug(std::string const& m)
|
|||||||
}
|
}
|
||||||
/// Debug end
|
/// Debug end
|
||||||
|
|
||||||
// Continuable forward declaration.
|
|
||||||
template<typename...>
|
template<typename...>
|
||||||
class Continuable;
|
class Continuable;
|
||||||
|
|
||||||
@ -107,6 +106,8 @@ namespace detail
|
|||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
|
/// A continuable provides useful methods to react on the result of callbacks
|
||||||
|
/// and allows to chain multiple callback calls to a chain.
|
||||||
template<typename... _ATy>
|
template<typename... _ATy>
|
||||||
class Continuable
|
class Continuable
|
||||||
{
|
{
|
||||||
@ -345,71 +346,6 @@ public:
|
|||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template <typename _CTy>
|
|
||||||
struct functional_corrector
|
|
||||||
{
|
|
||||||
static int correct(_CTy&&)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct void_wrap_trait<fu::identity<Args...>>
|
|
||||||
{
|
|
||||||
template<typename _CTy>
|
|
||||||
static std::function<Continuable<>(Args...)> wrap(_CTy&& functional)
|
|
||||||
{
|
|
||||||
return [functional](Args... args)
|
|
||||||
{
|
|
||||||
// Invoke the original callback
|
|
||||||
functional(std::forward<Args>(args)...);
|
|
||||||
|
|
||||||
// FIXME return make_empty_continuable()
|
|
||||||
// Return a fake continuable
|
|
||||||
return Continuable<>([](Callback<>&& callback)
|
|
||||||
{
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct convert_void_to_continuable<void>
|
|
||||||
{
|
|
||||||
typedef Continuable<> type;
|
|
||||||
|
|
||||||
template<typename Fn, typename... Args>
|
|
||||||
static type invoke(Fn functional, Args&&... args)
|
|
||||||
{
|
|
||||||
// Invoke the void returning functional
|
|
||||||
functional(std::forward<Args>(args)...);
|
|
||||||
|
|
||||||
// Return a fake void continuable
|
|
||||||
return type([](Callback<>&& callback)
|
|
||||||
{
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... _CTy>
|
|
||||||
struct convert_void_to_continuable<Continuable<_CTy...>>
|
|
||||||
{
|
|
||||||
typedef Continuable<_CTy...> type;
|
|
||||||
|
|
||||||
template<typename Fn, typename... Args>
|
|
||||||
static type invoke(Fn functional, Args&&... args)
|
|
||||||
{
|
|
||||||
// Invoke the functional as usual.
|
|
||||||
return functional(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/// A continuable provides useful methods to react on the result of callbacks
|
|
||||||
/// and allows to chain multiple callback calls to a chain.
|
|
||||||
|
|
||||||
template<typename _RTy, typename... _ATy>
|
template<typename _RTy, typename... _ATy>
|
||||||
struct ContinuableFactory;
|
struct ContinuableFactory;
|
||||||
|
|
||||||
@ -460,4 +396,69 @@ inline auto make_continuable()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template <typename _CTy>
|
||||||
|
struct functional_corrector
|
||||||
|
{
|
||||||
|
static int correct(_CTy&&)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
struct void_wrap_trait<fu::identity<Args...>>
|
||||||
|
{
|
||||||
|
template<typename _CTy>
|
||||||
|
static std::function<Continuable<>(Args...)> wrap(_CTy&& functional)
|
||||||
|
{
|
||||||
|
return [functional](Args... args)
|
||||||
|
{
|
||||||
|
// Invoke the original callback
|
||||||
|
functional(std::forward<Args>(args)...);
|
||||||
|
|
||||||
|
// FIXME return make_empty_continuable()
|
||||||
|
// Return a fake continuable
|
||||||
|
return Continuable<>([](Callback<>&& callback)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct convert_void_to_continuable<void>
|
||||||
|
{
|
||||||
|
typedef Continuable<> type;
|
||||||
|
|
||||||
|
template<typename Fn, typename... Args>
|
||||||
|
static type invoke(Fn functional, Args&&... args)
|
||||||
|
{
|
||||||
|
// Invoke the void returning functional
|
||||||
|
functional(std::forward<Args>(args)...);
|
||||||
|
|
||||||
|
// Return a fake void continuable
|
||||||
|
return type([](Callback<>&& callback)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... _CTy>
|
||||||
|
struct convert_void_to_continuable<Continuable<_CTy...>>
|
||||||
|
{
|
||||||
|
typedef Continuable<_CTy...> type;
|
||||||
|
|
||||||
|
template<typename Fn, typename... Args>
|
||||||
|
static type invoke(Fn functional, Args&&... args)
|
||||||
|
{
|
||||||
|
// Invoke the functional as usual.
|
||||||
|
return functional(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _CONTINUABLE_H_
|
#endif // _CONTINUABLE_H_
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user