Skip to content
18 changes: 16 additions & 2 deletions sycl/include/sycl/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ template <typename T = void> using bit_xor = std::bit_xor<T>;
// std:logical_and/std::logical_or with a non-void type returns bool,
// sycl requires returning T.
template <typename T = void> struct logical_and {
T operator()(const T &lhs, const T &rhs) const { return lhs && rhs; }
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
bool
#else
T
#endif
operator()(const T &lhs, const T &rhs) const {
return lhs && rhs;
}
};

template <> struct logical_and<void> : std::logical_and<void> {};

template <typename T = void> struct logical_or {
T operator()(const T &lhs, const T &rhs) const { return lhs || rhs; }
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
bool
#else
T
#endif
operator()(const T &lhs, const T &rhs) const {
return lhs || rhs;
}
};

template <> struct logical_or<void> : std::logical_or<void> {};
Expand Down
19 changes: 19 additions & 0 deletions sycl/test/basic_tests/logical_operations.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clang -D__INTEL_PREVIEW_BREAKING_CHANGES -fsycl -o - %s
// RUN: %clang -fsycl -o - %s

#include <cassert>
#include <sycl/functional.hpp>
#include <type_traits>

int main() {
const auto logicalAnd = sycl::logical_and<int>();
const auto logicalOr = sycl::logical_or<int>();
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
static_assert(std::is_same_v<decltype(logicalAnd(1, 2)), bool> == true);
static_assert(std::is_same_v<decltype(logicalOr(1, 2)), bool> == true);
#else
static_assert(std::is_same_v<decltype(logicalAnd(1, 2)), int> == true);
static_assert(std::is_same_v<decltype(logicalOr(1, 2)), int> == true);
#endif
return 0;
}
Loading