some thoughts about operator overloading

This commit is contained in:
Denis Blank 2015-08-09 01:25:19 +02:00 committed by Naios
parent 09145b0439
commit 775f9bb99a
3 changed files with 72 additions and 1 deletions

View File

@ -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
View 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);
}

View File

@ -303,8 +303,12 @@ public:
};
*/
void test_mockup();
int main(int /*argc*/, char** /*argv*/)
{
test_mockup();
// CopyMoveTracer tracer;
/*