more work on forward declaration

This commit is contained in:
Denis Blank 2015-06-22 14:44:54 +02:00 committed by Naios
parent bed62d03d6
commit fc127d805f
2 changed files with 82 additions and 72 deletions

View File

@ -101,8 +101,8 @@ namespace detail
template<typename Args> template<typename Args>
struct void_wrap_trait; struct void_wrap_trait;
template <typename _CTy> template <typename... _ATy>
struct functional_corrector; struct functional_traits;
} // detail } // detail
@ -221,7 +221,7 @@ public:
static_assert(std::is_rvalue_reference<_CTy&&>::value, static_assert(std::is_rvalue_reference<_CTy&&>::value,
"Given continuable must be passed as r-value!"); "Given continuable must be passed as r-value!");
return then(box_continuable_trait(std::forward<_CTy>(continuable))); return then(detail::functional_traits<_ATy...>::box_continuable_trait(std::forward<_CTy>(continuable)));
} }
template<typename... _CTy> template<typename... _CTy>
@ -327,83 +327,91 @@ inline auto make_continuable()
namespace detail namespace detail
{ {
/// Wrap void returning functionals to returns an empty continuable.
template <typename _CTy> template <typename _CTy>
static auto remove_void_trait(_CTy&& functional) struct continuable_traits;
-> typename std::enable_if<
std::is_void< template <typename _RTy, typename... _ATy>
fu::return_type_of_t< struct continuable_traits<std::function<_RTy(_ATy...)>>
typename std::decay<_CTy>::type {
>
>::value, };
/*decltype(
detail::void_wrap_trait< /// Continuable processing detail implementation
template <typename... _ATy>
struct functional_traits
{
/// Wrap void returning functionals to returns an empty continuable.
template <typename _CTy>
static auto remove_void_trait(_CTy&& functional)
-> typename std::enable_if<
std::is_void<
fu::return_type_of_t< fu::return_type_of_t<
typename std::decay<_CTy>::type typename std::decay<_CTy>::type
> >
>::wrap(std::declval<_CTy>()) >::value,
) /*decltype(
*/ detail::void_wrap_trait<
decltype( fu::return_type_of_t<
detail::functional_corrector<_CTy>::correct(std::declval<_CTy>()) typename std::decay<_CTy>::type
) >
// std::function<Continuable<>()> >::wrap(std::declval<_CTy>())
>::type )
{ */
/*return detail::void_wrap_trait< decltype(
fu::return_type_of_t< detail::functional_corrector<_CTy>::correct(std::declval<_CTy>())
typename std::decay<_CTy>::type )
> // std::function<Continuable<>()>
>::wrap(std::forward<_CTy>(functional));*/ >::type
return detail::functional_corrector<_CTy>::correct(std::forward<_CTy>(functional));
}
/// Route continuable returning functionals through.
/*template <typename _CTy>
static auto remove_void_trait(_CTy&& functional)
-> typename std::enable_if<
!std::is_void<
fu::return_type_of_t<
typename std::decay<_CTy>::type
>
>::value,
_CTy>::type
{
return std::forward<_CTy>(functional);
}*/
/// Wrap continuables into the continuable returning functional type.
template<typename _CTy>
auto box_continuable_trait(_CTy&& continuable)
-> typename std::enable_if<detail::is_continuable<typename std::decay<_CTy>::type>::value,
std::function<typename std::decay<_CTy>::type(_ATy...)>>::type
{
// Trick C++11 lambda capture rules for non copyable but moveable continuables.
std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable =
std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable));
// Create a fake function which returns the value on invoke.
return [shared_continuable](_ATy...)
{ {
return std::move(*shared_continuable); /*return detail::void_wrap_trait<
}; fu::return_type_of_t<
} typename std::decay<_CTy>::type
>
>::wrap(std::forward<_CTy>(functional));*/
return detail::functional_corrector<_CTy>::correct(std::forward<_CTy>(functional));
}
/// Route functionals through and forward to remove_void_trait /// Route continuable returning functionals through.
template<typename _CTy> /*template <typename _CTy>
auto box_continuable_trait(_CTy&& continuable) static auto remove_void_trait(_CTy&& functional)
-> typename std::enable_if<!detail::is_continuable<typename std::decay<_CTy>::type>::value, -> typename std::enable_if<
typename std::decay<_CTy>::type>::type !std::is_void<
{ fu::return_type_of_t<
return continuable; typename std::decay<_CTy>::type
} >
>::value,
_CTy>::type
{
return std::forward<_CTy>(functional);
}*/
template <typename _CTy> /// Wrap continuables into the continuable returning functional type.
struct functional_corrector template<typename _CTy>
{ static auto box_continuable_trait(_CTy&& continuable)
typedef fu::return_type_of_t<_CTy> return_t; -> typename std::enable_if<detail::is_continuable<typename std::decay<_CTy>::type>::value,
typedef fu::argument_type_of_t<_CTy> arg_t; std::function<typename std::decay<_CTy>::type(_ATy...)>>::type
{
// Trick C++11 lambda capture rules for non copyable but moveable continuables.
std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable =
std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable));
// Create a fake function which returns the value on invoke.
return [shared_continuable](_ATy...)
{
return std::move(*shared_continuable);
};
}
/// Route functionals through and forward to remove_void_trait
template<typename _CTy>
static auto box_continuable_trait(_CTy&& continuable)
-> typename std::enable_if<!detail::is_continuable<typename std::decay<_CTy>::type>::value,
typename std::decay<_CTy>::type>::type
{
return continuable;
}
template<typename _CTy>
static int correct(_CTy&&) static int correct(_CTy&&)
{ {
return 1; return 1;

View File

@ -230,9 +230,11 @@ int main(int /*argc*/, char** /*argv*/)
*/ */
/*
auto testres = Continuable<>::remove_void_trait([] auto testres = Continuable<>::remove_void_trait([]
{ {
}); });
*/
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
return 0; return 0;