Some minor things...

This commit is contained in:
Denis Blank 2016-10-13 00:12:05 +02:00
parent ccb99fc166
commit 103d8005f4
3 changed files with 74 additions and 58 deletions

View File

@ -26,7 +26,9 @@ target_compile_features(continuable
# Set up the test environment for testing # Set up the test environment for testing
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
add_executable(incubator "${CMAKE_CURRENT_LIST_DIR}/incubator.cpp") add_executable(incubator
"${CMAKE_CURRENT_LIST_DIR}/include/continuable/continuable.hpp"
"${CMAKE_CURRENT_LIST_DIR}/incubator.cpp")
target_link_libraries(incubator continuable) target_link_libraries(incubator continuable)
if (MSVC) if (MSVC)

View File

@ -173,12 +173,15 @@ auto tupleMerge(std::tuple<Left...>&& left,
std::move(left), std::move(right)); std::move(left), std::move(right));
} }
/// This class is responsible for holding an abstract copy- and
/// move-able ownership that is invalidated when the object
/// is moved to another instance.
class Ownership { class Ownership {
public: public:
Ownership() { } Ownership() { }
explicit Ownership(bool isOwning_) : isOwning(isOwning_) { } explicit Ownership(bool isOwning_) : isOwning(isOwning_) { }
Ownership(Ownership const&) = default; Ownership(Ownership const&) = default;
explicit Ownership(Ownership&& right) noexcept Ownership(Ownership&& right) noexcept
: isOwning(std::exchange(right.isOwning, false)) { }; : isOwning(std::exchange(right.isOwning, false)) { };
Ownership& operator = (Ownership const&) = default; Ownership& operator = (Ownership const&) = default;
Ownership& operator = (Ownership&& right) noexcept { Ownership& operator = (Ownership&& right) noexcept {
@ -196,6 +199,7 @@ public:
void invalidate() { void invalidate() {
isOwning = false; isOwning = false;
} }
private: private:
bool isOwning{ true }; bool isOwning{ true };
}; };
@ -479,29 +483,29 @@ auto make_continuable(Continuation&& continuation,
})); }));
} }
template<typename Data, typename Callback> template<typename Undecorated, typename Callback>
auto thenImpl(Data data, Callback&& callback) { auto thenImpl(Undecorated undecorated, Callback&& callback) {
auto next = appendCallback(std::move(data.continuation), auto next = appendCallback(std::move(undecorated.continuation),
std::forward<Callback>(callback)); std::forward<Callback>(callback));
using Decoration = DefaultDecoration<ContinuableData< using Decoration = DefaultDecoration<ContinuableData<
typename Data::Config::template ChangeContinuationTo<decltype(next)> typename Undecorated::Config::template ChangeContinuationTo<decltype(next)>
>>; >>;
return ContinuableBase<Decoration>(Decoration({ return ContinuableBase<Decoration>(Decoration({
std::move(data.ownership), std::move(undecorated.ownership),
std::move(next), std::move(next),
std::move(data.dispatcher) std::move(undecorated.dispatcher)
})); }));
} }
template<typename Data, typename NewDispatcher> template<typename Undecorated, typename NewDispatcher>
auto postImpl(Data data, NewDispatcher&& newDispatcher) { auto postImpl(Undecorated undecorated, NewDispatcher&& newDispatcher) {
using Decoration = DefaultDecoration<ContinuableData< using Decoration = DefaultDecoration<ContinuableData<
typename Data::Config::template typename Undecorated::Config::template
ChangeDispatcherTo<std::decay_t<NewDispatcher>> ChangeDispatcherTo<std::decay_t<NewDispatcher>>
>>; >>;
return ContinuableBase<Decoration>(Decoration({ return ContinuableBase<Decoration>(Decoration({
std::move(data.ownership), std::move(undecorated.ownership),
std::move(data.continuation), std::move(undecorated.continuation),
std::forward<NewDispatcher>(newDispatcher) std::forward<NewDispatcher>(newDispatcher)
})); }));
} }
@ -609,49 +613,4 @@ struct FailIfWrongArgs {
-> std::enable_if_t<N == sizeof...(Args)> { } -> std::enable_if_t<N == sizeof...(Args)> { }
}; };
int main(int, char**) {
auto dispatcher = SelfDispatcher{};
/*(makeTestContinuation() && makeTestContinuation())
.undecorateFor([]()
{
});*/
/*auto unwrapper = [](auto&&... args) {
return std::common_type<std::tuple<decltype(args)...>>{};
};*/
// using T = decltype(unwrap(FailIfWrongArgs<0>{}));
// using T = decltype(unwrap(std::declval<Inspector>()));
// T t{};
// auto combined = makeTestContinuation() && makeTestContinuation();
int res = 0;
makeTestContinuation()
.then([](std::string) {
return std::make_tuple(47, 46, 45);
})
// .post(dispatcher)
.then([](int val1, int val2, int val3) {
return val1 + val2 + val3;
})
.then([&](int val) {
res += val;
})
.then([] {
return makeTestContinuation();
})
.then([] (std::string arg) {
});
return res;
}
#endif // CONTINUABLE_HPP_INCLUDED__ #endif // CONTINUABLE_HPP_INCLUDED__

View File

@ -0,0 +1,55 @@
#include <functional>
#include "continuable/continuable.hpp"
template<typename... Args>
using continuable = decltype(make_continuable(std::declval<std::function<void(Args...)>>));
int main(int, char**) {
// continuable<int, int> c;
auto dispatcher = SelfDispatcher{};
/*(makeTestContinuation() && makeTestContinuation())
.undecorateFor([]()
{
});*/
/*auto unwrapper = [](auto&&... args) {
return std::common_type<std::tuple<decltype(args)...>>{};
};*/
// using T = decltype(unwrap(FailIfWrongArgs<0>{}));
// using T = decltype(unwrap(std::declval<Inspector>()));
// T t{};
// auto combined = makeTestContinuation() && makeTestContinuation();
int res = 0;
makeTestContinuation()
.then([](std::string) {
return std::make_tuple(47, 46, 45);
})
// .post(dispatcher)
.then([](int val1, int val2, int val3) {
return val1 + val2 + val3;
})
.then([&](int val) {
res += val;
})
.then([] {
return makeTestContinuation();
})
.then(makeTestContinuation())
.then([] (std::string arg) {
});
return res;
}