18 #ifndef viskores_internal_ArrayPortalValueReference_h
19 #define viskores_internal_ArrayPortalValueReference_h
45 template <
typename ArrayPortalType>
46 struct ArrayPortalValueReference
48 using ValueType =
typename ArrayPortalType::ValueType;
52 ArrayPortalValueReference(
const ArrayPortalType& portal,
viskores::Id index)
60 ArrayPortalValueReference(
const ArrayPortalValueReference& ref)
68 ValueType
Get()
const {
return this->Portal.Get(this->
Index); }
72 operator ValueType()
const {
return this->
Get(); }
82 void Set(ValueType&& value)
const { this->Portal.Set(this->
Index, std::move(value)); }
86 void Set(
const ValueType& value)
const { this->Portal.Set(this->
Index, value); }
89 void Swap(
const ArrayPortalValueReference<ArrayPortalType>& rhs)
const noexcept
94 const ValueType aValue = *
this;
107 const ArrayPortalValueReference<ArrayPortalType>& operator=(ValueType&& value)
const
109 this->Set(std::move(value));
115 const ArrayPortalValueReference<ArrayPortalType>& operator=(
const ValueType& value)
const
127 const ArrayPortalValueReference<ArrayPortalType>& rhs)
129 this->Set(
static_cast<ValueType
>(rhs.Portal.Get(rhs.Index)));
134 template <
typename T>
137 ValueType lhs = this->
Get();
143 template <
typename T>
144 VISKORES_EXEC_CONT ValueType operator+=(
const ArrayPortalValueReference<T>& rhs)
const
146 ValueType lhs = this->
Get();
153 template <
typename T>
156 ValueType lhs = this->
Get();
162 template <
typename T>
163 VISKORES_EXEC_CONT ValueType operator-=(
const ArrayPortalValueReference<T>& rhs)
const
165 ValueType lhs = this->
Get();
172 template <
typename T>
175 ValueType lhs = this->
Get();
181 template <
typename T>
182 VISKORES_EXEC_CONT ValueType operator*=(
const ArrayPortalValueReference<T>& rhs)
const
184 ValueType lhs = this->
Get();
191 template <
typename T>
194 ValueType lhs = this->
Get();
200 template <
typename T>
201 VISKORES_EXEC_CONT ValueType operator/=(
const ArrayPortalValueReference<T>& rhs)
const
203 ValueType lhs = this->
Get();
210 template <
typename T>
213 ValueType lhs = this->
Get();
219 template <
typename T>
220 VISKORES_EXEC_CONT ValueType operator%=(
const ArrayPortalValueReference<T>& rhs)
const
222 ValueType lhs = this->
Get();
229 template <
typename T>
232 ValueType lhs = this->
Get();
238 template <
typename T>
239 VISKORES_EXEC_CONT ValueType operator&=(
const ArrayPortalValueReference<T>& rhs)
const
241 ValueType lhs = this->
Get();
248 template <
typename T>
251 ValueType lhs = this->
Get();
257 template <
typename T>
258 VISKORES_EXEC_CONT ValueType operator|=(
const ArrayPortalValueReference<T>& rhs)
const
260 ValueType lhs = this->
Get();
267 template <
typename T>
270 ValueType lhs = this->
Get();
276 template <
typename T>
277 VISKORES_EXEC_CONT ValueType operator^=(
const ArrayPortalValueReference<T>& rhs)
const
279 ValueType lhs = this->
Get();
286 template <
typename T>
289 ValueType lhs = this->
Get();
295 template <
typename T>
296 VISKORES_EXEC_CONT ValueType operator>>=(
const ArrayPortalValueReference<T>& rhs)
const
298 ValueType lhs = this->
Get();
305 template <
typename T>
308 ValueType lhs = this->
Get();
314 template <
typename T>
315 VISKORES_EXEC_CONT ValueType operator<<=(
const ArrayPortalValueReference<T>& rhs)
const
317 ValueType lhs = this->
Get();
338 const ArrayPortalType& Portal;
344 template <
typename T>
345 void swap(
const viskores::internal::ArrayPortalValueReference<T>& a,
346 const viskores::internal::ArrayPortalValueReference<T>& b)
351 template <
typename T>
352 void swap(
const viskores::internal::ArrayPortalValueReference<T>& a,
353 typename viskores::internal::ArrayPortalValueReference<T>::ValueType& b)
355 using ValueType =
typename viskores::internal::ArrayPortalValueReference<T>::ValueType;
356 const ValueType tmp = a;
361 template <
typename T>
362 void swap(
typename viskores::internal::ArrayPortalValueReference<T>::ValueType& a,
363 const viskores::internal::ArrayPortalValueReference<T>& b)
365 using ValueType =
typename viskores::internal::ArrayPortalValueReference<T>::ValueType;
366 const ValueType tmp = b;
377 template <
typename LhsPortalType>
379 const typename LhsPortalType::ValueType& rhs)
380 -> decltype(lhs.Get() == rhs)
382 return lhs.Get() == rhs;
385 template <
typename LhsPortalType,
typename RhsPortalType>
387 const ArrayPortalValueReference<RhsPortalType>& rhs)
388 -> decltype(lhs.Get() == rhs.Get())
390 return lhs.Get() == rhs.Get();
393 template <
typename RhsPortalType>
395 const ArrayPortalValueReference<RhsPortalType>& rhs)
396 -> decltype(lhs == rhs.Get())
398 return lhs == rhs.Get();
402 template <
typename LhsPortalType>
404 const typename LhsPortalType::ValueType& rhs)
405 -> decltype(lhs.Get() != rhs)
407 return lhs.Get() != rhs;
410 template <
typename LhsPortalType,
typename RhsPortalType>
412 const ArrayPortalValueReference<RhsPortalType>& rhs)
413 -> decltype(lhs.Get() != rhs.Get())
415 return lhs.Get() != rhs.Get();
418 template <
typename RhsPortalType>
420 const ArrayPortalValueReference<RhsPortalType>& rhs)
421 -> decltype(lhs != rhs.Get())
423 return lhs != rhs.Get();
427 template <
typename LhsPortalType>
428 VISKORES_EXEC_CONT auto operator<(
const ArrayPortalValueReference<LhsPortalType>& lhs,
429 const typename LhsPortalType::ValueType& rhs)
430 -> decltype(lhs.Get() < rhs)
432 return lhs.Get() < rhs;
435 template <
typename LhsPortalType,
typename RhsPortalType>
436 VISKORES_EXEC_CONT auto operator<(
const ArrayPortalValueReference<LhsPortalType>& lhs,
437 const ArrayPortalValueReference<RhsPortalType>& rhs)
438 -> decltype(lhs.Get() < rhs.Get())
440 return lhs.Get() < rhs.Get();
443 template <
typename RhsPortalType>
445 const ArrayPortalValueReference<RhsPortalType>& rhs)
446 -> decltype(lhs < rhs.Get())
448 return lhs < rhs.Get();
452 template <
typename LhsPortalType>
453 VISKORES_EXEC_CONT auto operator>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
454 const typename LhsPortalType::ValueType& rhs)
455 -> decltype(lhs.Get() > rhs)
457 return lhs.Get() > rhs;
460 template <
typename LhsPortalType,
typename RhsPortalType>
461 VISKORES_EXEC_CONT auto operator>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
462 const ArrayPortalValueReference<RhsPortalType>& rhs)
463 -> decltype(lhs.Get() > rhs.Get())
465 return lhs.Get() > rhs.Get();
468 template <
typename RhsPortalType>
470 const ArrayPortalValueReference<RhsPortalType>& rhs)
471 -> decltype(lhs > rhs.Get())
473 return lhs > rhs.Get();
477 template <
typename LhsPortalType>
478 VISKORES_EXEC_CONT auto operator<=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
479 const typename LhsPortalType::ValueType& rhs)
480 -> decltype(lhs.Get() <= rhs)
482 return lhs.Get() <= rhs;
485 template <
typename LhsPortalType,
typename RhsPortalType>
486 VISKORES_EXEC_CONT auto operator<=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
487 const ArrayPortalValueReference<RhsPortalType>& rhs)
488 -> decltype(lhs.Get() <= rhs.Get())
490 return lhs.Get() <= rhs.Get();
493 template <
typename RhsPortalType>
495 const ArrayPortalValueReference<RhsPortalType>& rhs)
496 -> decltype(lhs <= rhs.Get())
498 return lhs <= rhs.Get();
502 template <
typename LhsPortalType>
503 VISKORES_EXEC_CONT auto operator>=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
504 const typename LhsPortalType::ValueType& rhs)
505 -> decltype(lhs.Get() >= rhs)
507 return lhs.Get() >= rhs;
510 template <
typename LhsPortalType,
typename RhsPortalType>
511 VISKORES_EXEC_CONT auto operator>=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
512 const ArrayPortalValueReference<RhsPortalType>& rhs)
513 -> decltype(lhs.Get() >= rhs.Get())
515 return lhs.Get() >= rhs.Get();
518 template <
typename RhsPortalType>
520 const ArrayPortalValueReference<RhsPortalType>& rhs)
521 -> decltype(lhs >= rhs.Get())
523 return lhs >= rhs.Get();
527 template <
typename LhsPortalType>
529 const typename LhsPortalType::ValueType& rhs)
530 -> decltype(lhs.Get() + rhs)
532 return lhs.Get() + rhs;
535 template <
typename LhsPortalType,
typename RhsPortalType>
537 const ArrayPortalValueReference<RhsPortalType>& rhs)
538 -> decltype(lhs.Get() + rhs.Get())
540 return lhs.Get() + rhs.Get();
543 template <
typename RhsPortalType>
545 const ArrayPortalValueReference<RhsPortalType>& rhs)
546 -> decltype(lhs + rhs.Get())
548 return lhs + rhs.Get();
552 template <
typename LhsPortalType>
554 const typename LhsPortalType::ValueType& rhs)
555 -> decltype(lhs.Get() - rhs)
557 return lhs.Get() - rhs;
560 template <
typename LhsPortalType,
typename RhsPortalType>
562 const ArrayPortalValueReference<RhsPortalType>& rhs)
563 -> decltype(lhs.Get() - rhs.Get())
565 return lhs.Get() - rhs.Get();
568 template <
typename RhsPortalType>
570 const ArrayPortalValueReference<RhsPortalType>& rhs)
571 -> decltype(lhs - rhs.Get())
573 return lhs - rhs.Get();
577 template <
typename LhsPortalType>
579 const typename LhsPortalType::ValueType& rhs)
580 -> decltype(lhs.Get() * rhs)
582 return lhs.Get() * rhs;
585 template <
typename LhsPortalType,
typename RhsPortalType>
587 const ArrayPortalValueReference<RhsPortalType>& rhs)
588 -> decltype(lhs.Get() * rhs.Get())
590 return lhs.Get() * rhs.Get();
593 template <
typename RhsPortalType>
595 const ArrayPortalValueReference<RhsPortalType>& rhs)
596 -> decltype(lhs * rhs.Get())
598 return lhs * rhs.Get();
602 template <
typename LhsPortalType>
604 const typename LhsPortalType::ValueType& rhs)
605 -> decltype(lhs.Get() / rhs)
607 return lhs.Get() / rhs;
610 template <
typename LhsPortalType,
typename RhsPortalType>
612 const ArrayPortalValueReference<RhsPortalType>& rhs)
613 -> decltype(lhs.Get() / rhs.Get())
615 return lhs.Get() / rhs.Get();
618 template <
typename RhsPortalType>
620 const ArrayPortalValueReference<RhsPortalType>& rhs)
621 -> decltype(lhs / rhs.Get())
623 return lhs / rhs.Get();
627 template <
typename LhsPortalType>
628 VISKORES_EXEC_CONT auto operator%(
const ArrayPortalValueReference<LhsPortalType>& lhs,
629 const typename LhsPortalType::ValueType& rhs)
630 -> decltype(lhs.Get() % rhs)
632 return lhs.Get() % rhs;
635 template <
typename LhsPortalType,
typename RhsPortalType>
636 VISKORES_EXEC_CONT auto operator%(
const ArrayPortalValueReference<LhsPortalType>& lhs,
637 const ArrayPortalValueReference<RhsPortalType>& rhs)
638 -> decltype(lhs.Get() % rhs.Get())
640 return lhs.Get() % rhs.Get();
643 template <
typename RhsPortalType>
645 const ArrayPortalValueReference<RhsPortalType>& rhs)
646 -> decltype(lhs % rhs.Get())
648 return lhs % rhs.Get();
652 template <
typename LhsPortalType>
653 VISKORES_EXEC_CONT auto operator^(
const ArrayPortalValueReference<LhsPortalType>& lhs,
654 const typename LhsPortalType::ValueType& rhs)
655 -> decltype(lhs.Get() ^ rhs)
657 return lhs.Get() ^ rhs;
660 template <
typename LhsPortalType,
typename RhsPortalType>
661 VISKORES_EXEC_CONT auto operator^(
const ArrayPortalValueReference<LhsPortalType>& lhs,
662 const ArrayPortalValueReference<RhsPortalType>& rhs)
663 -> decltype(lhs.Get() ^ rhs.Get())
665 return lhs.Get() ^ rhs.Get();
668 template <
typename RhsPortalType>
670 const ArrayPortalValueReference<RhsPortalType>& rhs)
671 -> decltype(lhs ^ rhs.Get())
673 return lhs ^ rhs.Get();
677 template <
typename LhsPortalType>
679 const typename LhsPortalType::ValueType& rhs)
680 -> decltype(lhs.Get() | rhs)
682 return lhs.Get() | rhs;
685 template <
typename LhsPortalType,
typename RhsPortalType>
687 const ArrayPortalValueReference<RhsPortalType>& rhs)
688 -> decltype(lhs.Get() | rhs.Get())
690 return lhs.Get() | rhs.Get();
693 template <
typename RhsPortalType>
695 const ArrayPortalValueReference<RhsPortalType>& rhs)
696 -> decltype(lhs | rhs.Get())
698 return lhs | rhs.Get();
702 template <
typename LhsPortalType>
704 const typename LhsPortalType::ValueType& rhs)
705 -> decltype(lhs.Get() & rhs)
707 return lhs.Get() & rhs;
710 template <
typename LhsPortalType,
typename RhsPortalType>
712 const ArrayPortalValueReference<RhsPortalType>& rhs)
713 -> decltype(lhs.Get() & rhs.Get())
715 return lhs.Get() & rhs.Get();
718 template <
typename RhsPortalType>
720 const ArrayPortalValueReference<RhsPortalType>& rhs)
721 -> decltype(lhs & rhs.Get())
723 return lhs & rhs.Get();
727 template <
typename LhsPortalType>
729 const typename LhsPortalType::ValueType& rhs)
730 -> decltype(lhs.Get() << rhs)
732 return lhs.Get() << rhs;
735 template <
typename LhsPortalType,
typename RhsPortalType>
737 const ArrayPortalValueReference<RhsPortalType>& rhs)
738 -> decltype(lhs.Get() << rhs.Get())
740 return lhs.Get() << rhs.Get();
743 template <
typename RhsPortalType>
745 const ArrayPortalValueReference<RhsPortalType>& rhs)
746 -> decltype(lhs << rhs.Get())
748 return lhs << rhs.Get();
752 template <
typename LhsPortalType>
753 VISKORES_EXEC_CONT auto operator>>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
754 const typename LhsPortalType::ValueType& rhs)
755 -> decltype(lhs.Get() >> rhs)
757 return lhs.Get() >> rhs;
760 template <
typename LhsPortalType,
typename RhsPortalType>
761 VISKORES_EXEC_CONT auto operator>>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
762 const ArrayPortalValueReference<RhsPortalType>& rhs)
763 -> decltype(lhs.Get() >> rhs.Get())
765 return lhs.Get() >> rhs.Get();
768 template <
typename RhsPortalType>
770 const ArrayPortalValueReference<RhsPortalType>& rhs)
771 -> decltype(lhs >> rhs.Get())
773 return lhs >> rhs.Get();
777 template <
typename PortalType>
779 -> decltype(~ref.Get())
785 template <
typename PortalType>
787 -> decltype(!ref.Get())
793 template <
typename LhsPortalType>
794 VISKORES_EXEC_CONT auto operator&&(
const ArrayPortalValueReference<LhsPortalType>& lhs,
795 const typename LhsPortalType::ValueType& rhs)
796 -> decltype(lhs.Get() && rhs)
798 return lhs.Get() && rhs;
801 template <
typename LhsPortalType,
typename RhsPortalType>
802 VISKORES_EXEC_CONT auto operator&&(
const ArrayPortalValueReference<LhsPortalType>& lhs,
803 const ArrayPortalValueReference<RhsPortalType>& rhs)
804 -> decltype(lhs.Get() && rhs.Get())
806 return lhs.Get() && rhs.Get();
809 template <
typename RhsPortalType>
811 const ArrayPortalValueReference<RhsPortalType>& rhs)
812 -> decltype(lhs && rhs.Get())
814 return lhs && rhs.Get();
818 template <
typename LhsPortalType>
819 VISKORES_EXEC_CONT auto operator||(
const ArrayPortalValueReference<LhsPortalType>& lhs,
820 const typename LhsPortalType::ValueType& rhs)
821 -> decltype(lhs.Get() || rhs)
823 return lhs.Get() || rhs;
826 template <
typename LhsPortalType,
typename RhsPortalType>
827 VISKORES_EXEC_CONT auto operator||(
const ArrayPortalValueReference<LhsPortalType>& lhs,
828 const ArrayPortalValueReference<RhsPortalType>& rhs)
829 -> decltype(lhs.Get() || rhs.Get())
831 return lhs.Get() || rhs.Get();
834 template <
typename RhsPortalType>
836 const ArrayPortalValueReference<RhsPortalType>& rhs)
837 -> decltype(lhs || rhs.Get())
839 return lhs || rhs.Get();
850 template <
typename PortalType>
851 struct TypeTraits<
viskores::internal::ArrayPortalValueReference<PortalType>>
853 typename viskores::internal::ArrayPortalValueReference<PortalType>::ValueType>
857 template <
typename PortalType>
858 struct VecTraits<
viskores::internal::ArrayPortalValueReference<PortalType>>
860 typename viskores::internal::ArrayPortalValueReference<PortalType>::ValueType>
866 #endif //viskores_internal_ArrayPortalValueReference_h