Skip to content

Commit

Permalink
Make always not default constructible with primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Jun 26, 2016
1 parent d9917dd commit ddb7f22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion include/fit/always.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

namespace fit { namespace always_detail {

template<class T>
template<class T, class=void>
struct always_base
{
T x;
Expand All @@ -94,6 +94,22 @@ struct always_base
}
};

template<class T>
struct always_base<T, typename std::enable_if<std::is_arithmetic<T>::value>::type>
{
T x;

constexpr always_base(T xp) : x(xp)
{}

template<class... As>
constexpr typename detail::unwrap_reference<T>::type
operator()(As&&...) const
{
return this->x;
}
};

#if FIT_NO_CONSTEXPR_VOID
#define FIT_ALWAYS_VOID_RETURN fit::always_detail::always_base<void>::void_
#else
Expand Down
6 changes: 6 additions & 0 deletions test/always.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ FIT_TEST_CASE()
FIT_STATIC_TEST_CHECK(ten(1,2,3,4,5) == 10);
FIT_TEST_CHECK(ten(1,2,3,4,5) == 10);
}

FIT_TEST_CASE()
{
auto f = fit::always(10);
STATIC_ASSERT_NOT_DEFAULT_CONSTRUCTIBLE(decltype(f));
}

0 comments on commit ddb7f22

Please sign in to comment.