mirror of
https://github.com/Naios/continuable.git
synced 2026-02-15 06:39:49 +08:00
more tests
This commit is contained in:
parent
d11c564f7f
commit
519ab69d40
@ -357,6 +357,7 @@ namespace detail
|
|||||||
typedef Tuple tuple;
|
typedef Tuple tuple;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
template<typename _CTy, typename... _ATy>
|
template<typename _CTy, typename... _ATy>
|
||||||
struct continuable_returner
|
struct continuable_returner
|
||||||
{
|
{
|
||||||
@ -381,6 +382,7 @@ namespace detail
|
|||||||
return std::move(returning_continuable);
|
return std::move(returning_continuable);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
/// Continuable processing detail implementation
|
/// Continuable processing detail implementation
|
||||||
template <typename... _ATy>
|
template <typename... _ATy>
|
||||||
@ -440,22 +442,16 @@ namespace detail
|
|||||||
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!");
|
||||||
|
|
||||||
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.
|
// Trick C++11 lambda capture rules for non copyable but moveable continuables.
|
||||||
// TODO Use the stack instead of heap variables.
|
// TODO Use the stack instead of heap variables.
|
||||||
/*std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable =
|
std::shared_ptr<typename std::decay<_CTy>::type> shared_continuable =
|
||||||
std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable));*/
|
std::make_shared<typename std::decay<_CTy>::type>(std::forward<_CTy>(continuable));
|
||||||
|
|
||||||
// Create a fake function which returns the value on invoke.
|
// Create a fake function which returns the value on invoke.
|
||||||
/*return [shared_continuable](_ATy&&...)
|
return [shared_continuable](_ATy&&...)
|
||||||
{
|
{
|
||||||
return std::move(*shared_continuable);
|
return std::move(*shared_continuable);
|
||||||
};*/
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Route functionals through
|
/// Route functionals through
|
||||||
|
|||||||
39
test.cpp
39
test.cpp
@ -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*/)
|
int main(int /*argc*/, char** /*argv*/)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -411,18 +435,15 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
|
|
||||||
conv_test_1(1, 1);
|
conv_test_1(1, 1);
|
||||||
|
|
||||||
struct TestFunctor
|
|
||||||
{
|
|
||||||
void operator() (int)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TestFunctor fn;
|
|
||||||
|
|
||||||
static_assert(fu::is_unwrappable<TestFunctor>::value, "not unwrappable!");
|
continuable_returner<std::unique_ptr<int>> fn(std::unique_ptr<int>(new int(5)));
|
||||||
|
|
||||||
std::function<void(int)> fntest = std::move(fn);
|
continuable_returner<std::unique_ptr<int>> other_fn = std::move(fn);
|
||||||
|
|
||||||
|
// static_assert(fu::is_unwrappable<TestFunctor>::value, "not unwrappable!");
|
||||||
|
|
||||||
|
// std::function<void(int)> fntest = std::move(fn);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user