Skip to content

Commit

Permalink
Capture use compressed_pair
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Apr 27, 2016
1 parent 24e4e0a commit 88c28bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
12 changes: 6 additions & 6 deletions include/fit/capture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define FIT_GUARD_CAPTURE_H

#include <fit/detail/callable_base.hpp>
#include <fit/detail/compressed_pair.hpp>
#include <fit/reveal.hpp>
#include <fit/pack.hpp>
#include <fit/always.hpp>
Expand Down Expand Up @@ -73,22 +74,21 @@ namespace fit {
namespace detail {

template<class F, class Pack>
struct capture_invoke : detail::callable_base<F>, Pack
struct capture_invoke : detail::compressed_pair<detail::callable_base<F>, Pack>
{
typedef capture_invoke fit_rewritable1_tag;
template<class X, class Y>
constexpr capture_invoke(X&& x, Y&& y) : detail::callable_base<F>(FIT_FORWARD(X)(x)), Pack(FIT_FORWARD(Y)(y))
{}
typedef detail::compressed_pair<detail::callable_base<F>, Pack> base;
FIT_INHERIT_CONSTRUCTOR(capture_invoke, base)
template<class... Ts>
constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const
{
return always_ref(*this)(xs...);
return this->first(xs...);
}

template<class... Ts>
constexpr const Pack& get_pack(Ts&&...xs) const
{
return always_ref(*this)(xs...);
return this->second(xs...);
}

template<class Failure, class... Ts>
Expand Down
18 changes: 17 additions & 1 deletion test/capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ FIT_TEST_CASE()

FIT_TEST_CASE()
{
fit::capture(fit::identity)(fit::identity)();
auto id = fit::identity;
auto f = fit::capture_decay(fit::identity)(fit::identity);
static_assert(FIT_IS_DEFAULT_CONSTRUCTIBLE(decltype(id)), "Id not default constructible");
static_assert(FIT_IS_DEFAULT_CONSTRUCTIBLE(decltype(f)), "Not default constructible");
f();
}

FIT_TEST_CASE()
{
auto f = fit::capture(fit::identity)(fit::identity);
f();
}

FIT_TEST_CASE()
{
auto f = fit::capture_forward(fit::identity)(fit::identity);
f();
}

0 comments on commit 88c28bf

Please sign in to comment.