22 #ifndef RAJA_operators_HPP
23 #define RAJA_operators_HPP
25 #include "RAJA/config.hpp"
31 #include <type_traits>
32 #if defined(RAJA_CHECK_LIMITS)
59 std::conditional_t<std::is_floating_point<std::decay_t<T>>::value,
63 template<
typename Arg1,
typename Arg2,
typename Result>
71 template<
typename Argument,
typename Result>
78 template<
typename Arg1,
typename Arg2>
90 static constexpr
const bool value =
91 std::is_unsigned<T>::value && std::is_integral<T>::value;
97 static constexpr
const bool value =
98 !std::is_unsigned<T>::value && std::is_integral<T>::value;
106 template<
typename T,
bool GPU = false>
167 template<
typename T,
bool isInt,
bool isSigned,
bool isFP,
bool gpu = false>
200 template<
typename T,
bool gpu = false>
204 std::is_integral<T>::value,
205 std::is_signed<T>::value,
206 std::is_floating_point<T>::value,
222 template<
typename T,
typename U,
bool lhsLarger>
226 template<
typename T,
typename U>
232 template<
typename T,
typename U>
239 template<
typename T,
typename U>
249 template<
typename T,
typename Enable =
void>
255 typename
std::enable_if<std::is_integral<T>::value &&
256 !std::is_unsigned<T>::value>::type>
260 #ifdef RAJA_COMPILER_MSVC
261 #pragma warning(disable : 4309)
263 return static_cast<T
>(1llu << ((8llu *
sizeof(T)) - 1llu));
264 #ifdef RAJA_COMPILER_MSVC
265 #pragma warning(default : 4309)
271 #ifdef RAJA_COMPILER_MSVC
272 #pragma warning(disable : 4309)
274 return static_cast<T
>(~(1llu << ((8llu *
sizeof(T)) - 1llu)));
275 #ifdef RAJA_COMPILER_MSVC
276 #pragma warning(default : 4309)
284 typename
std::enable_if<std::is_integral<T>::value &&
285 std::is_unsigned<T>::value>::type>
289 return static_cast<T
>(0);
294 #ifdef RAJA_COMPILER_MSVC
295 #pragma warning(disable : 4309)
297 return static_cast<T
>(0xFFFFFFFFFFFFFFFF);
298 #ifdef RAJA_COMPILER_MSVC
299 #pragma warning(default : 4309)
338 #if defined(RAJA_CHECK_LIMITS)
340 constexpr
bool check()
346 static_assert(check<char>(),
"limits for char is broken");
347 static_assert(check<unsigned char>(),
"limits for unsigned char is broken");
348 static_assert(check<short>(),
"limits for short is broken");
349 static_assert(check<unsigned short>(),
"limits for unsigned short is broken");
350 static_assert(check<int>(),
"limits for int is broken");
351 static_assert(check<unsigned int>(),
"limits for unsigned int is broken");
352 static_assert(check<long>(),
"limits for long is broken");
353 static_assert(check<unsigned long>(),
"limits for unsigned long is broken");
354 static_assert(check<long int>(),
"limits for long int is broken");
355 static_assert(check<unsigned long int>(),
356 "limits for unsigned long int is broken");
357 static_assert(check<long long>(),
"limits for long long is broken");
358 static_assert(check<unsigned long long>(),
359 "limits for unsigned long long is broken");
364 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
369 const Arg2& rhs)
const
371 return Ret {lhs} + rhs;
378 return str <<
"RAJA::operators::plus{}";
382 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
386 const Arg2& rhs)
const
388 return Ret {lhs} - rhs;
393 return str <<
"RAJA::operators::minus{}";
397 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
403 const Arg2& rhs)
const
405 return Ret {lhs} * rhs;
412 return str <<
"RAJA::operators::multiplies{}";
416 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
420 const Arg2& rhs)
const
422 return Ret {lhs} / rhs;
427 return str <<
"RAJA::operators::divides{}";
431 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
435 const Arg2& rhs)
const
437 return Ret {lhs} % rhs;
442 return str <<
"RAJA::operators::modulus{}";
448 template<
typename Arg1,
typename Arg2 = Arg1>
453 const Arg2& rhs)
const
462 return str <<
"RAJA::operators::logical_and{}";
466 template<
typename Arg1,
typename Arg2 = Arg1>
471 const Arg2& rhs)
const
480 return str <<
"RAJA::operators::logical_or{}";
494 return str <<
"RAJA::operators::logical_not{}";
500 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
504 const Arg2& rhs)
const
513 return str <<
"RAJA::operators::bit_or{}";
517 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
521 const Arg2& rhs)
const
530 return str <<
"RAJA::operators::bit_and{}";
534 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
538 const Arg2& rhs)
const
545 return str <<
"RAJA::operators::bit_xor{}";
556 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
561 const Arg2& rhs)
const
563 return (rhs < lhs) ? rhs : lhs;
573 return str <<
"RAJA::operators::minimum{}";
577 template<
typename Ret,
typename Arg1 = Ret,
typename Arg2 = Arg1>
582 const Arg2& rhs)
const
584 return (lhs < rhs) ? rhs : lhs;
594 return str <<
"RAJA::operators::maximum{}";
600 template<
typename Arg1,
typename Arg2 = Arg1>
604 const Arg2& rhs)
const
611 return str <<
"RAJA::operators::equal_to{}";
615 template<
typename Arg1,
typename Arg2 = Arg1>
619 const Arg2& rhs)
const
626 return str <<
"RAJA::operators::not_equal_to{}";
630 template<
typename Arg1,
typename Arg2 = Arg1>
634 const Arg2& rhs)
const
641 return str <<
"RAJA::operators::greater{}";
645 template<
typename Arg1,
typename Arg2 = Arg1>
649 const Arg2& rhs)
const
656 return str <<
"RAJA::operators::less{}";
660 template<
typename Arg1,
typename Arg2 = Arg1>
664 const Arg2& rhs)
const
672 return str <<
"RAJA::operators::greater_equal{}";
676 template<
typename Arg1,
typename Arg2 = Arg1>
680 const Arg2& rhs)
const
687 return str <<
"RAJA::operators::less_equal{}";
693 template<
typename Ret,
typename Orig = Ret>
703 return str <<
"RAJA::operators::identity{}";
707 template<
typename T,
typename U>
718 return str <<
"RAJA::operators::project1st{}";
722 template<
typename T,
typename U = T>
733 return str <<
"RAJA::operators::project2nd{}";
743 std::is_base_of<detail::associative_tag, T>::value;
750 std::is_base_of<detail::fp_associative_tag, T>::value;
753 template<
typename Arg1,
typename Arg2 = Arg1>
757 typename types::larger<
758 typename types::larger_of<Arg1, Arg2>::type>::type>
762 return str <<
"RAJA::operators::safe_plus{}";
771 template<
typename Function,
773 typename Arg1 = Return,
774 typename Arg2 = Arg1>
776 : DefineConcept(::RAJA::concepts::convertible_to<Return>(
777 camp::val<Function>()(camp::val<Arg1>(), camp::val<Arg2>()))) {};
779 template<
typename Function,
typename Return,
typename Arg = Return>
780 struct UnaryFunction : DefineConcept(::RAJA::concepts::convertible_to<Return>(
781 camp::val<Function>()(camp::val<Arg>()))) {};
786 template<
typename Fun,
typename Ret,
typename T,
typename U>
788 ::RAJA::concepts::requires_<BinaryFunction, Ret, T, U>;
790 template<
typename Fun,
typename Ret,
typename T>
796 namespace type_traits
Header file for RAJA concept definitions.
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_UNUSED_ARG(x)
Definition: macros.hpp:97
::RAJA::concepts::requires_< UnaryFunction, Ret, T > is_unary_function
Definition: Operators.hpp:791
::RAJA::concepts::requires_< BinaryFunction, Ret, T, U > is_binary_function
Definition: Operators.hpp:788
std::conditional_t< std::is_floating_point< std::decay_t< T > >::value, fp_associative_tag, associative_tag > associative_or_fp_associative_tag
Definition: Operators.hpp:61
DefineTypeTraitFromConcept(is_range_constructible, RAJA::concepts::RangeConstructible)
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result min(Args... args)
Definition: foldl.hpp:161
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result max(Args... args)
Definition: foldl.hpp:155
Definition: ListSegment.hpp:416
Definition: Operators.hpp:777
Definition: Operators.hpp:781
Definition: Operators.hpp:519
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:520
friend std::ostream & operator<<(std::ostream &str, bit_and const &)
Definition: Operators.hpp:528
static constexpr RAJA_HOST_DEVICE Ret identity()
Definition: Operators.hpp:526
Definition: Operators.hpp:502
static constexpr RAJA_HOST_DEVICE Ret identity()
Definition: Operators.hpp:509
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:503
friend std::ostream & operator<<(std::ostream &str, bit_or const &)
Definition: Operators.hpp:511
Definition: Operators.hpp:536
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:537
friend std::ostream & operator<<(std::ostream &str, bit_xor const &)
Definition: Operators.hpp:543
Definition: Operators.hpp:50
Definition: Operators.hpp:65
Arg2 second_argument_type
Definition: Operators.hpp:67
Arg1 first_argument_type
Definition: Operators.hpp:66
Result result_type
Definition: Operators.hpp:68
Definition: Operators.hpp:80
Definition: Operators.hpp:54
Definition: Operators.hpp:73
Argument argument_type
Definition: Operators.hpp:74
Result result_type
Definition: Operators.hpp:75
Definition: Operators.hpp:418
friend std::ostream & operator<<(std::ostream &str, divides const &)
Definition: Operators.hpp:425
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:419
Definition: Operators.hpp:602
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:603
friend std::ostream & operator<<(std::ostream &str, equal_to const &)
Definition: Operators.hpp:609
Definition: Operators.hpp:662
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:663
friend std::ostream & operator<<(std::ostream &str, greater_equal const &)
Definition: Operators.hpp:669
Definition: Operators.hpp:632
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:633
friend std::ostream & operator<<(std::ostream &str, greater const &)
Definition: Operators.hpp:639
Definition: Operators.hpp:695
friend std::ostream & operator<<(std::ostream &str, identity const &)
Definition: Operators.hpp:701
constexpr RAJA_HOST_DEVICE Ret operator()(const Orig &lhs) const
Definition: Operators.hpp:696
Definition: Operators.hpp:741
static constexpr const bool value
Definition: Operators.hpp:742
Definition: Operators.hpp:748
static constexpr const bool value
Definition: Operators.hpp:749
Definition: Operators.hpp:678
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:679
friend std::ostream & operator<<(std::ostream &str, less_equal const &)
Definition: Operators.hpp:685
Definition: Operators.hpp:647
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:648
friend std::ostream & operator<<(std::ostream &str, less const &)
Definition: Operators.hpp:654
RAJA_INLINE static constexpr RAJA_HOST_DEVICE T max()
Definition: Operators.hpp:269
RAJA_INLINE static constexpr RAJA_HOST_DEVICE T min()
Definition: Operators.hpp:258
RAJA_INLINE static constexpr RAJA_HOST_DEVICE T max()
Definition: Operators.hpp:292
RAJA_INLINE static constexpr RAJA_HOST_DEVICE T min()
Definition: Operators.hpp:287
RAJA_INLINE static constexpr RAJA_HOST_DEVICE double max()
Definition: Operators.hpp:320
RAJA_INLINE static constexpr RAJA_HOST_DEVICE double min()
Definition: Operators.hpp:315
RAJA_INLINE static constexpr RAJA_HOST_DEVICE float max()
Definition: Operators.hpp:309
RAJA_INLINE static constexpr RAJA_HOST_DEVICE float min()
Definition: Operators.hpp:307
RAJA_INLINE static constexpr RAJA_HOST_DEVICE long double max()
Definition: Operators.hpp:331
RAJA_INLINE static constexpr RAJA_HOST_DEVICE long double min()
Definition: Operators.hpp:326
Definition: Operators.hpp:250
Definition: Operators.hpp:451
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:452
friend std::ostream & operator<<(std::ostream &str, logical_and const &)
Definition: Operators.hpp:460
static constexpr RAJA_HOST_DEVICE bool identity()
Definition: Operators.hpp:458
Definition: Operators.hpp:486
friend std::ostream & operator<<(std::ostream &str, logical_not const &)
Definition: Operators.hpp:492
constexpr RAJA_HOST_DEVICE bool operator()(const T &lhs) const
Definition: Operators.hpp:487
Definition: Operators.hpp:469
static constexpr RAJA_HOST_DEVICE bool identity()
Definition: Operators.hpp:476
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:470
friend std::ostream & operator<<(std::ostream &str, logical_or const &)
Definition: Operators.hpp:478
Definition: Operators.hpp:580
static constexpr RAJA_HOST_DEVICE Ret identity()
Definition: Operators.hpp:587
friend std::ostream & operator<<(std::ostream &str, maximum const &)
Definition: Operators.hpp:592
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:581
Definition: Operators.hpp:559
friend std::ostream & operator<<(std::ostream &str, minimum const &)
Definition: Operators.hpp:571
static constexpr RAJA_HOST_DEVICE Ret identity()
Definition: Operators.hpp:566
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:560
Definition: Operators.hpp:384
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:385
friend std::ostream & operator<<(std::ostream &str, minus const &)
Definition: Operators.hpp:391
Definition: Operators.hpp:433
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:434
friend std::ostream & operator<<(std::ostream &str, modulus const &)
Definition: Operators.hpp:440
Definition: Operators.hpp:400
friend std::ostream & operator<<(std::ostream &str, multiplies const &)
Definition: Operators.hpp:410
static constexpr RAJA_HOST_DEVICE Ret identity()
Definition: Operators.hpp:408
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:402
Definition: Operators.hpp:617
friend std::ostream & operator<<(std::ostream &str, not_equal_to const &)
Definition: Operators.hpp:624
constexpr RAJA_HOST_DEVICE bool operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:618
Definition: Operators.hpp:367
constexpr RAJA_HOST_DEVICE Ret operator()(const Arg1 &lhs, const Arg2 &rhs) const
Definition: Operators.hpp:368
friend std::ostream & operator<<(std::ostream &str, plus const &)
Definition: Operators.hpp:376
static constexpr RAJA_HOST_DEVICE Ret identity()
Definition: Operators.hpp:374
Definition: Operators.hpp:709
friend std::ostream & operator<<(std::ostream &str, project1st const &)
Definition: Operators.hpp:716
constexpr RAJA_HOST_DEVICE T operator()(const T &lhs, const U &RAJA_UNUSED_ARG(rhs)) const
Definition: Operators.hpp:710
Definition: Operators.hpp:724
constexpr RAJA_HOST_DEVICE U operator()(const T &RAJA_UNUSED_ARG(lhs), const U &rhs) const
Definition: Operators.hpp:725
friend std::ostream & operator<<(std::ostream &str, project2nd const &)
Definition: Operators.hpp:731
Definition: Operators.hpp:759
friend std::ostream & operator<<(std::ostream &str, safe_plus const &)
Definition: Operators.hpp:760
U type
Definition: Operators.hpp:235
T type
Definition: Operators.hpp:229
Definition: Operators.hpp:224
long double type
Definition: Operators.hpp:186
double type
Definition: Operators.hpp:192
uint64_t type
Definition: Operators.hpp:174
int64_t type
Definition: Operators.hpp:180
Definition: Operators.hpp:169
Definition: Operators.hpp:96
static constexpr const bool value
Definition: Operators.hpp:97
Definition: Operators.hpp:89
static constexpr const bool value
Definition: Operators.hpp:90
double type
Definition: Operators.hpp:161
long double type
Definition: Operators.hpp:155
double type
Definition: Operators.hpp:149
int32_t type
Definition: Operators.hpp:137
int64_t type
Definition: Operators.hpp:143
int16_t type
Definition: Operators.hpp:131
uint32_t type
Definition: Operators.hpp:119
uint64_t type
Definition: Operators.hpp:125
uint16_t type
Definition: Operators.hpp:113
Definition: Operators.hpp:241
typename detail::larger_of< T, U,(size_of< T >::value > size_of< U >::value)>::type type
Definition: Operators.hpp:243
Definition: Operators.hpp:108
Definition: Operators.hpp:202
typename detail::largest< T, std::is_integral< T >::value, std::is_signed< T >::value, std::is_floating_point< T >::value, gpu >::type type
Definition: Operators.hpp:207
Definition: Operators.hpp:212
@ value
Definition: Operators.hpp:215