Skip to content

Commit

Permalink
Make sure indirection doesn't remove constness
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Mar 23, 2016
1 parent 2f1fd0c commit 088f81a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/fit/indirect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct indirect_adaptor<F*>
{}

template<class... Ts>
constexpr const F& base_function(Ts&&...) const
constexpr F& base_function(Ts&&...) const
{
return *f;
}
Expand All @@ -114,7 +114,7 @@ struct indirect_adaptor<F*>
constexpr FIT_SFINAE_RESULT(F, id_<Ts>...)
operator()(Ts&&... xs) const FIT_SFINAE_RETURNS
(
(FIT_MANGLE_CAST(const F&)(FIT_CONST_THIS->base_function(xs...)))(FIT_FORWARD(Ts)(xs)...)
(FIT_MANGLE_CAST(F&)(FIT_CONST_THIS->base_function(xs...)))(FIT_FORWARD(Ts)(xs)...)
);
};

Expand Down
26 changes: 26 additions & 0 deletions test/indirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ FIT_TEST_CASE()
FIT_TEST_CHECK(3 == fit::indirect(&f)(1, 2));
FIT_TEST_CHECK(3 == fit::reveal(fit::indirect(&f))(1, 2));
}

struct mutable_function
{
mutable_function() : value(0) {}
void operator()(int a) { value += a; }
int value;
};

FIT_TEST_CASE()
{
auto mf = mutable_function{};
fit::indirect(&mf)(15);
fit::indirect(&mf)(2);
FIT_TEST_CHECK(mf.value == 17);
}


FIT_TEST_CASE()
{
auto mf = std::make_shared<mutable_function>();
fit::indirect(mf)(15);
fit::indirect(mf)(2);
FIT_TEST_CHECK(mf->value == 17);
}


0 comments on commit 088f81a

Please sign in to comment.