Skip to content

Commit

Permalink
Fix issue #50
Browse files Browse the repository at this point in the history
  • Loading branch information
MBkkt authored and Naios committed Jun 1, 2022
1 parent a24bdcf commit f569a63
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
26 changes: 19 additions & 7 deletions include/function2/function2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ using void_t = typename deduce_to_void<T...>::type;
template <typename T>
using unrefcv_t = std::remove_cv_t<std::remove_reference_t<T>>;

template <typename...>
struct lazy_and;

template <typename B1>
struct lazy_and<B1> : B1 {};

template <typename B1, typename B2>
struct lazy_and<B1, B2> : std::conditional<B1::value, B2, B1>::type {};

// template <typename B1, typename B2, typename B3, typename... Bn>
// struct lazy_and<B1, B2, B3, Bn...>
// : std::conditional<B1::value, lazy_and<B2, B3, Bn...>, B1>::type {};

// Copy enabler helper class
template <bool /*Copyable*/>
struct copyable {};
Expand Down Expand Up @@ -1369,13 +1382,12 @@ template <typename T, typename Signature,
typename Trait =
type_erasure::invocation_table::function_trait<Signature>>
struct accepts_one
: std::integral_constant<
bool, invocation::can_invoke<typename Trait::template callable<T>,
typename Trait::arguments>::value &&
invocation::is_noexcept_correct<
Trait::is_noexcept::value,
typename Trait::template callable<T>,
typename Trait::arguments>::value> {};
: detail::lazy_and< // both are std::integral_constant
invocation::can_invoke<typename Trait::template callable<T>,
typename Trait::arguments>,
invocation::is_noexcept_correct<Trait::is_noexcept::value,
typename Trait::template callable<T>,
typename Trait::arguments>> {};

/// Deduces to a true_type if the type T provides all signatures
template <typename T, typename Signatures, typename = void>
Expand Down
12 changes: 12 additions & 0 deletions test/noexcept-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ TYPED_TEST(AllNoExceptTests, NoExceptCallSuceeds) {
ASSERT_EQ(left(), 12345);
}

TYPED_TEST(AllNoExceptTests, NoexceptDontAffectOverloads) {
using Type = typename TestFixture::template left_t<void() noexcept>;
struct Storage {
Storage(Type) {
}
Storage(Storage&&) {
}
};
Storage s1{[]() noexcept {}};
Storage s2{std::move(s1)};
}

#ifndef TESTS_NO_DEATH_TESTS
TYPED_TEST(AllNoExceptTests, CallAbortsIfEmptyAndNoExcept) {
typename TestFixture::template left_t<bool() noexcept> left;
Expand Down

0 comments on commit f569a63

Please sign in to comment.