Skip to content

Commit

Permalink
Remove is_valid, use std::declval
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasleibner authored and kris-jusiak committed Feb 4, 2025
1 parent 1a07b02 commit 2841097
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
22 changes: 3 additions & 19 deletions include/boost/ut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,28 +464,12 @@ struct function_traits<R (T::*)(TArgs...) const> {
using args = list<TArgs...>;
};

template <class T>
T&& declval();
template <class... Ts, class TExpr>
constexpr auto is_valid(TExpr expr) -> decltype(expr(declval<Ts...>()),
bool()) {
return true;
}
template <class...>
constexpr auto is_valid(...) -> bool {
return false;
}

template <class T>
inline constexpr auto has_user_print = is_valid<T>(
[](auto t) -> decltype(void(declval<std::ostringstream&>() << t)) {});

template <class T, class = void>
struct has_static_member_object_value : std::false_type {};

template <class T>
struct has_static_member_object_value<T,
std::void_t<decltype(declval<T>().value)>>
std::void_t<decltype(std::declval<T>().value)>>
: std::bool_constant<!std::is_member_pointer_v<decltype(&T::value)> &&
!std::is_function_v<decltype(T::value)>> {};

Expand All @@ -498,7 +482,7 @@ struct has_static_member_object_epsilon : std::false_type {};

template <class T>
struct has_static_member_object_epsilon<
T, std::void_t<decltype(declval<T>().epsilon)>>
T, std::void_t<decltype(std::declval<T>().epsilon)>>
: std::bool_constant<!std::is_member_pointer_v<decltype(&T::epsilon)> &&
!std::is_function_v<decltype(T::epsilon)>> {};

Expand Down Expand Up @@ -2312,7 +2296,7 @@ struct test {
template <class Test>
requires(!std::convertible_to<Test, void (*)(std::string_view)>)
constexpr auto operator=(Test _test)
-> decltype(_test(type_traits::declval<std::string_view>())) {
-> decltype(_test(std::declval<std::string_view>())) {
return _test(name);
}
};
Expand Down
12 changes: 0 additions & 12 deletions test/ut/ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,6 @@ int main() { // NOLINT(readability-function-size)
test_has_member_object::public_static_member_function_epsilon>);
}

{
struct foo {
int value;
};
struct bar {};
constexpr auto value = [](auto t) -> decltype(t.value, void()) {};
static_assert(type_traits::is_valid<foo>(value));
static_assert(not type_traits::is_valid<bar>(value));
static_assert(not type_traits::is_valid<int>(value));
static_assert(not type_traits::is_valid<void>(value));
}

{
static_assert("void" == reflection::type_name<void>());
static_assert("int" == reflection::type_name<int>());
Expand Down

0 comments on commit 2841097

Please sign in to comment.