mirror of
https://github.com/Naios/continuable.git
synced 2025-12-08 01:36:46 +08:00
some thoughts about operator overloading
This commit is contained in:
parent
09145b0439
commit
775f9bb99a
@ -57,7 +57,7 @@ add_library(continue STATIC ${LIB_SOURCES})
|
||||
|
||||
include_directories(include dep/concurrentqueue)
|
||||
|
||||
set(TEST_SOURCES test.cpp)
|
||||
set(TEST_SOURCES test.cpp mockup.cpp)
|
||||
|
||||
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