more tests

This commit is contained in:
Naios 2015-07-14 22:17:04 +02:00
parent 5bab44b936
commit b6c5bd5136
2 changed files with 36 additions and 19 deletions

View File

@ -357,6 +357,7 @@ namespace detail
typedef Tuple tuple;
};
/*
template<typename _CTy, typename... _ATy>
struct continuable_returner
{
@ -381,6 +382,7 @@ namespace detail
return std::move(returning_continuable);
}
};
*/
/// Continuable processing detail implementation
template <typename... _ATy>
@ -440,22 +442,16 @@ namespace detail
static_assert(std::is_rvalue_reference<_CTy&&>::value,
"Given continuable must be passed as r-value!");
std::function<typename std::decay<_CTy>::type(_ATy...)> returning_function;
continuable_returner<_CTy, _ATy...> returner(std::forward<_CTy>(continuable));
return std::move(returning_function);
// Trick C++11 lambda capture rules for non copyable but moveable continuables.
// TODO Use the stack instead of heap variables.
/*std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable =
std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable));*/
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 [shared_continuable](_ATy&&...)
{
return std::move(*shared_continuable);
};*/
};
}
/// Route functionals through

View File

@ -127,6 +127,30 @@ namespace detail
}
*/
template<typename _CTy, typename... _ATy>
class continuable_returner
{
_CTy returning_continuable;
public:
continuable_returner(_CTy&& returning_continuable_)
: returning_continuable(std::move(returning_continuable_)) { }
continuable_returner& operator= (continuable_returner&) = delete;
continuable_returner& operator= (continuable_returner&& right)
{
// returning_continuable = std::move(right.returning_continuable);
return *this;
};
auto operator()(_ATy&&...)
-> _CTy
{
return std::move(returning_continuable);
}
};
int main(int /*argc*/, char** /*argv*/)
{
/*
@ -411,18 +435,15 @@ int main(int /*argc*/, char** /*argv*/)
conv_test_1(1, 1);
struct TestFunctor
{
void operator() (int)
{
}
};
TestFunctor fn;
continuable_returner<std::unique_ptr<int>> fn(std::unique_ptr<int>(new int(5)));
static_assert(fu::is_unwrappable<TestFunctor>::value, "not unwrappable!");
continuable_returner<std::unique_ptr<int>> other_fn = std::move(fn);
std::function<void(int)> fntest = std::move(fn);
// static_assert(fu::is_unwrappable<TestFunctor>::value, "not unwrappable!");
// std::function<void(int)> fntest = std::move(fn);
return 0;
}