Skip to content

Commit

Permalink
added disjunction, properly handle case T==void
Browse files Browse the repository at this point in the history
  • Loading branch information
pf committed Aug 5, 2023
1 parent 47a6a9b commit 97a1fc2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 8 additions & 6 deletions dlib/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ namespace dlib
template <
class T,
class E,
bool copyable = ((std::is_void<T>::value || std::is_copy_constructible<T>::value) && std::is_copy_constructible<E>::value),
bool moveable = ((std::is_void<T>::value || std::is_move_constructible<T>::value) && std::is_move_constructible<E>::value)
bool copyable = (disjunction<std::is_void<T>, std::is_copy_constructible<T>>::value && std::is_copy_constructible<E>::value),
bool moveable = (disjunction<std::is_void<T>, std::is_move_constructible<T>>::value && std::is_move_constructible<E>::value)
>
struct expected_delete_constructors
{
Expand Down Expand Up @@ -732,11 +732,13 @@ namespace dlib
template <
class T,
class E,
bool copyable = ((std::is_void<T>::value || (std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value)) &&
std::is_copy_constructible<E>::value &&
bool copyable = (disjunction<std::is_void<T>, std::is_copy_constructible<T>>::value &&
disjunction<std::is_void<T>, std::is_copy_assignable<T>>::value &&
std::is_copy_constructible<E>::value &&
std::is_copy_assignable<E>::value),
bool moveable = ((std::is_void<T>::value || (std::is_move_constructible<T>::value && std::is_move_assignable<T>::value)) &&
std::is_move_constructible<E>::value &&
bool moveable = (disjunction<std::is_void<T>, std::is_move_constructible<T>>::value &&
disjunction<std::is_void<T>, std::is_move_assignable<T>>::value &&
std::is_move_constructible<E>::value &&
std::is_move_assignable<E>::value)
>
struct expected_delete_assign
Expand Down
11 changes: 11 additions & 0 deletions dlib/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ namespace dlib
template<class B1, class... Bn>
struct conjunction<B1, Bn...> : std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};

// ----------------------------------------------------------------------------------------

template<class...>
struct disjunction : std::false_type {};

template<class B1>
struct disjunction<B1> : B1 {};

template<class B1, class... Bn>
struct disjunction<B1, Bn...> : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> {};

// ----------------------------------------------------------------------------------------

template <typename ...Types>
Expand Down

0 comments on commit 97a1fc2

Please sign in to comment.