mirror of
https://github.com/Naios/continuable.git
synced 2026-02-08 18:56:40 +08:00
some thoughts about operator overloading
This commit is contained in:
parent
e1d8b2692a
commit
e2c6e3bb30
@ -57,7 +57,7 @@ add_library(continue STATIC ${LIB_SOURCES})
|
|||||||
|
|
||||||
include_directories(include dep/concurrentqueue)
|
include_directories(include dep/concurrentqueue)
|
||||||
|
|
||||||
set(TEST_SOURCES test.cpp)
|
set(TEST_SOURCES test.cpp mockup.cpp)
|
||||||
|
|
||||||
add_executable(continue_test ${TEST_SOURCES})
|
add_executable(continue_test ${TEST_SOURCES})
|
||||||
|
|
||||||
|
|||||||
67
mockup.cpp
Normal file
67
mockup.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
template <typename...>
|
||||||
|
struct Continuable;
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
Continuable<> make_continuable(Args&&...)
|
||||||
|
{
|
||||||
|
return Continuable<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename...>
|
||||||
|
struct Continuable
|
||||||
|
{
|
||||||
|
template <typename... Args>
|
||||||
|
Continuable then(Args&&...)
|
||||||
|
{
|
||||||
|
return Continuable();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
Continuable all(Args&&...)
|
||||||
|
{
|
||||||
|
return Continuable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... LeftArgs, typename... RightArgs>
|
||||||
|
Continuable<> operator&& (Continuable<LeftArgs...>&&, Continuable<RightArgs...>&&)
|
||||||
|
{
|
||||||
|
return Continuable<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... LeftArgs, typename... RightArgs>
|
||||||
|
Continuable<> operator|| (Continuable<LeftArgs...>&&, Continuable<RightArgs...>&&)
|
||||||
|
{
|
||||||
|
return Continuable<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Continuable<> http_request(std::string const& /*URL*/)
|
||||||
|
{
|
||||||
|
return make_continuable([=](std::function<void(std::string)>&& callback)
|
||||||
|
{
|
||||||
|
// Do request...
|
||||||
|
|
||||||
|
callback("some HTTP content");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_mockup()
|
||||||
|
{
|
||||||
|
Continuable<> c1 = make_continuable([]
|
||||||
|
{
|
||||||
|
});
|
||||||
|
|
||||||
|
Continuable<> c2 = make_continuable([]
|
||||||
|
{
|
||||||
|
});
|
||||||
|
|
||||||
|
Continuable<> c3 = make_continuable([]
|
||||||
|
{
|
||||||
|
});
|
||||||
|
|
||||||
|
Continuable<> c11 = (std::move(c1) && std::move(c2)) || std::move(c3);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user