10 #ifndef vtk_m_internal_ArrayPortalValueReference_h
11 #define vtk_m_internal_ArrayPortalValueReference_h
37 template <
typename ArrayPortalType>
38 struct ArrayPortalValueReference
40 using ValueType =
typename ArrayPortalType::ValueType;
44 ArrayPortalValueReference(
const ArrayPortalType& portal,
vtkm::Id index)
52 ArrayPortalValueReference(
const ArrayPortalValueReference& ref)
60 ValueType
Get()
const {
return this->Portal.Get(this->
Index); }
64 operator ValueType()
const {
return this->
Get(); }
74 void Set(ValueType&& value)
const { this->Portal.Set(this->
Index, std::move(value)); }
78 void Set(
const ValueType& value)
const { this->Portal.Set(this->
Index, value); }
81 void Swap(
const ArrayPortalValueReference<ArrayPortalType>& rhs)
const noexcept
86 const ValueType aValue = *
this;
99 const ArrayPortalValueReference<ArrayPortalType>& operator=(ValueType&& value)
const
101 this->Set(std::move(value));
107 const ArrayPortalValueReference<ArrayPortalType>& operator=(
const ValueType& value)
const
118 VTKM_EXEC_CONT ArrayPortalValueReference<ArrayPortalType>& operator=(
119 const ArrayPortalValueReference<ArrayPortalType>& rhs)
121 this->Set(
static_cast<ValueType
>(rhs.Portal.Get(rhs.Index)));
126 template <
typename T>
129 ValueType lhs = this->
Get();
135 template <
typename T>
136 VTKM_EXEC_CONT ValueType operator+=(
const ArrayPortalValueReference<T>& rhs)
const
138 ValueType lhs = this->
Get();
145 template <
typename T>
148 ValueType lhs = this->
Get();
154 template <
typename T>
155 VTKM_EXEC_CONT ValueType operator-=(
const ArrayPortalValueReference<T>& rhs)
const
157 ValueType lhs = this->
Get();
164 template <
typename T>
167 ValueType lhs = this->
Get();
173 template <
typename T>
174 VTKM_EXEC_CONT ValueType operator*=(
const ArrayPortalValueReference<T>& rhs)
const
176 ValueType lhs = this->
Get();
183 template <
typename T>
186 ValueType lhs = this->
Get();
192 template <
typename T>
193 VTKM_EXEC_CONT ValueType operator/=(
const ArrayPortalValueReference<T>& rhs)
const
195 ValueType lhs = this->
Get();
202 template <
typename T>
205 ValueType lhs = this->
Get();
211 template <
typename T>
212 VTKM_EXEC_CONT ValueType operator%=(
const ArrayPortalValueReference<T>& rhs)
const
214 ValueType lhs = this->
Get();
221 template <
typename T>
224 ValueType lhs = this->
Get();
230 template <
typename T>
231 VTKM_EXEC_CONT ValueType operator&=(
const ArrayPortalValueReference<T>& rhs)
const
233 ValueType lhs = this->
Get();
240 template <
typename T>
243 ValueType lhs = this->
Get();
249 template <
typename T>
250 VTKM_EXEC_CONT ValueType operator|=(
const ArrayPortalValueReference<T>& rhs)
const
252 ValueType lhs = this->
Get();
259 template <
typename T>
262 ValueType lhs = this->
Get();
268 template <
typename T>
269 VTKM_EXEC_CONT ValueType operator^=(
const ArrayPortalValueReference<T>& rhs)
const
271 ValueType lhs = this->
Get();
278 template <
typename T>
281 ValueType lhs = this->
Get();
287 template <
typename T>
288 VTKM_EXEC_CONT ValueType operator>>=(
const ArrayPortalValueReference<T>& rhs)
const
290 ValueType lhs = this->
Get();
297 template <
typename T>
300 ValueType lhs = this->
Get();
306 template <
typename T>
307 VTKM_EXEC_CONT ValueType operator<<=(
const ArrayPortalValueReference<T>& rhs)
const
309 ValueType lhs = this->
Get();
329 const ArrayPortalType& Portal;
335 template <
typename T>
336 void swap(
const vtkm::internal::ArrayPortalValueReference<T>& a,
337 const vtkm::internal::ArrayPortalValueReference<T>& b)
342 template <
typename T>
343 void swap(
const vtkm::internal::ArrayPortalValueReference<T>& a,
344 typename vtkm::internal::ArrayPortalValueReference<T>::ValueType& b)
346 using ValueType =
typename vtkm::internal::ArrayPortalValueReference<T>::ValueType;
347 const ValueType tmp = a;
352 template <
typename T>
353 void swap(
typename vtkm::internal::ArrayPortalValueReference<T>::ValueType& a,
354 const vtkm::internal::ArrayPortalValueReference<T>& b)
356 using ValueType =
typename vtkm::internal::ArrayPortalValueReference<T>::ValueType;
357 const ValueType tmp = b;
368 template <
typename LhsPortalType>
370 const typename LhsPortalType::ValueType& rhs)
371 -> decltype(lhs.Get() == rhs)
373 return lhs.Get() == rhs;
376 template <
typename LhsPortalType,
typename RhsPortalType>
378 const ArrayPortalValueReference<RhsPortalType>& rhs)
379 -> decltype(lhs.Get() == rhs.Get())
381 return lhs.Get() == rhs.Get();
384 template <
typename RhsPortalType>
386 const ArrayPortalValueReference<RhsPortalType>& rhs)
387 -> decltype(lhs == rhs.Get())
389 return lhs == rhs.Get();
393 template <
typename LhsPortalType>
395 const typename LhsPortalType::ValueType& rhs)
396 -> decltype(lhs.Get() != rhs)
398 return lhs.Get() != rhs;
401 template <
typename LhsPortalType,
typename RhsPortalType>
403 const ArrayPortalValueReference<RhsPortalType>& rhs)
404 -> decltype(lhs.Get() != rhs.Get())
406 return lhs.Get() != rhs.Get();
409 template <
typename RhsPortalType>
411 const ArrayPortalValueReference<RhsPortalType>& rhs)
412 -> decltype(lhs != rhs.Get())
414 return lhs != rhs.Get();
418 template <
typename LhsPortalType>
419 VTKM_EXEC_CONT auto operator<(
const ArrayPortalValueReference<LhsPortalType>& lhs,
420 const typename LhsPortalType::ValueType& rhs)
421 -> decltype(lhs.Get() < rhs)
423 return lhs.Get() < rhs;
426 template <
typename LhsPortalType,
typename RhsPortalType>
427 VTKM_EXEC_CONT auto operator<(
const ArrayPortalValueReference<LhsPortalType>& lhs,
428 const ArrayPortalValueReference<RhsPortalType>& rhs)
429 -> decltype(lhs.Get() < rhs.Get())
431 return lhs.Get() < rhs.Get();
434 template <
typename RhsPortalType>
435 VTKM_EXEC_CONT auto operator<(
const typename RhsPortalType::ValueType& lhs,
436 const ArrayPortalValueReference<RhsPortalType>& rhs)
437 -> decltype(lhs < rhs.Get())
439 return lhs < rhs.Get();
443 template <
typename LhsPortalType>
444 VTKM_EXEC_CONT auto operator>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
445 const typename LhsPortalType::ValueType& rhs)
446 -> decltype(lhs.Get() > rhs)
448 return lhs.Get() > rhs;
451 template <
typename LhsPortalType,
typename RhsPortalType>
452 VTKM_EXEC_CONT auto operator>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
453 const ArrayPortalValueReference<RhsPortalType>& rhs)
454 -> decltype(lhs.Get() > rhs.Get())
456 return lhs.Get() > rhs.Get();
459 template <
typename RhsPortalType>
460 VTKM_EXEC_CONT auto operator>(
const typename RhsPortalType::ValueType& lhs,
461 const ArrayPortalValueReference<RhsPortalType>& rhs)
462 -> decltype(lhs > rhs.Get())
464 return lhs > rhs.Get();
468 template <
typename LhsPortalType>
469 VTKM_EXEC_CONT auto operator<=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
470 const typename LhsPortalType::ValueType& rhs)
471 -> decltype(lhs.Get() <= rhs)
473 return lhs.Get() <= rhs;
476 template <
typename LhsPortalType,
typename RhsPortalType>
477 VTKM_EXEC_CONT auto operator<=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
478 const ArrayPortalValueReference<RhsPortalType>& rhs)
479 -> decltype(lhs.Get() <= rhs.Get())
481 return lhs.Get() <= rhs.Get();
484 template <
typename RhsPortalType>
485 VTKM_EXEC_CONT auto operator<=(
const typename RhsPortalType::ValueType& lhs,
486 const ArrayPortalValueReference<RhsPortalType>& rhs)
487 -> decltype(lhs <= rhs.Get())
489 return lhs <= rhs.Get();
493 template <
typename LhsPortalType>
494 VTKM_EXEC_CONT auto operator>=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
495 const typename LhsPortalType::ValueType& rhs)
496 -> decltype(lhs.Get() >= rhs)
498 return lhs.Get() >= rhs;
501 template <
typename LhsPortalType,
typename RhsPortalType>
502 VTKM_EXEC_CONT auto operator>=(
const ArrayPortalValueReference<LhsPortalType>& lhs,
503 const ArrayPortalValueReference<RhsPortalType>& rhs)
504 -> decltype(lhs.Get() >= rhs.Get())
506 return lhs.Get() >= rhs.Get();
509 template <
typename RhsPortalType>
510 VTKM_EXEC_CONT auto operator>=(
const typename RhsPortalType::ValueType& lhs,
511 const ArrayPortalValueReference<RhsPortalType>& rhs)
512 -> decltype(lhs >= rhs.Get())
514 return lhs >= rhs.Get();
518 template <
typename LhsPortalType>
520 const typename LhsPortalType::ValueType& rhs)
521 -> decltype(lhs.Get() + rhs)
523 return lhs.Get() + rhs;
526 template <
typename LhsPortalType,
typename RhsPortalType>
528 const ArrayPortalValueReference<RhsPortalType>& rhs)
529 -> decltype(lhs.Get() + rhs.Get())
531 return lhs.Get() + rhs.Get();
534 template <
typename RhsPortalType>
536 const ArrayPortalValueReference<RhsPortalType>& rhs)
537 -> decltype(lhs + rhs.Get())
539 return lhs + rhs.Get();
543 template <
typename LhsPortalType>
545 const typename LhsPortalType::ValueType& rhs)
546 -> decltype(lhs.Get() - rhs)
548 return lhs.Get() - rhs;
551 template <
typename LhsPortalType,
typename RhsPortalType>
553 const ArrayPortalValueReference<RhsPortalType>& rhs)
554 -> decltype(lhs.Get() - rhs.Get())
556 return lhs.Get() - rhs.Get();
559 template <
typename RhsPortalType>
561 const ArrayPortalValueReference<RhsPortalType>& rhs)
562 -> decltype(lhs - rhs.Get())
564 return lhs - rhs.Get();
568 template <
typename LhsPortalType>
570 const typename LhsPortalType::ValueType& rhs)
571 -> decltype(lhs.Get() * rhs)
573 return lhs.Get() * rhs;
576 template <
typename LhsPortalType,
typename RhsPortalType>
578 const ArrayPortalValueReference<RhsPortalType>& rhs)
579 -> decltype(lhs.Get() * rhs.Get())
581 return lhs.Get() * rhs.Get();
584 template <
typename RhsPortalType>
586 const ArrayPortalValueReference<RhsPortalType>& rhs)
587 -> decltype(lhs * rhs.Get())
589 return lhs * rhs.Get();
593 template <
typename LhsPortalType>
595 const typename LhsPortalType::ValueType& rhs)
596 -> decltype(lhs.Get() / rhs)
598 return lhs.Get() / rhs;
601 template <
typename LhsPortalType,
typename RhsPortalType>
603 const ArrayPortalValueReference<RhsPortalType>& rhs)
604 -> decltype(lhs.Get() / rhs.Get())
606 return lhs.Get() / rhs.Get();
609 template <
typename RhsPortalType>
611 const ArrayPortalValueReference<RhsPortalType>& rhs)
612 -> decltype(lhs / rhs.Get())
614 return lhs / rhs.Get();
618 template <
typename LhsPortalType>
619 VTKM_EXEC_CONT auto operator%(
const ArrayPortalValueReference<LhsPortalType>& lhs,
620 const typename LhsPortalType::ValueType& rhs)
621 -> decltype(lhs.Get() % rhs)
623 return lhs.Get() % rhs;
626 template <
typename LhsPortalType,
typename RhsPortalType>
627 VTKM_EXEC_CONT auto operator%(
const ArrayPortalValueReference<LhsPortalType>& lhs,
628 const ArrayPortalValueReference<RhsPortalType>& rhs)
629 -> decltype(lhs.Get() % rhs.Get())
631 return lhs.Get() % rhs.Get();
634 template <
typename RhsPortalType>
635 VTKM_EXEC_CONT auto operator%(
const typename RhsPortalType::ValueType& lhs,
636 const ArrayPortalValueReference<RhsPortalType>& rhs)
637 -> decltype(lhs % rhs.Get())
639 return lhs % rhs.Get();
643 template <
typename LhsPortalType>
644 VTKM_EXEC_CONT auto operator^(
const ArrayPortalValueReference<LhsPortalType>& lhs,
645 const typename LhsPortalType::ValueType& rhs)
646 -> decltype(lhs.Get() ^ rhs)
648 return lhs.Get() ^ rhs;
651 template <
typename LhsPortalType,
typename RhsPortalType>
652 VTKM_EXEC_CONT auto operator^(
const ArrayPortalValueReference<LhsPortalType>& lhs,
653 const ArrayPortalValueReference<RhsPortalType>& rhs)
654 -> decltype(lhs.Get() ^ rhs.Get())
656 return lhs.Get() ^ rhs.Get();
659 template <
typename RhsPortalType>
660 VTKM_EXEC_CONT auto operator^(
const typename RhsPortalType::ValueType& lhs,
661 const ArrayPortalValueReference<RhsPortalType>& rhs)
662 -> decltype(lhs ^ rhs.Get())
664 return lhs ^ rhs.Get();
668 template <
typename LhsPortalType>
670 const typename LhsPortalType::ValueType& rhs)
671 -> decltype(lhs.Get() | rhs)
673 return lhs.Get() | rhs;
676 template <
typename LhsPortalType,
typename RhsPortalType>
678 const ArrayPortalValueReference<RhsPortalType>& rhs)
679 -> decltype(lhs.Get() | rhs.Get())
681 return lhs.Get() | rhs.Get();
684 template <
typename RhsPortalType>
686 const ArrayPortalValueReference<RhsPortalType>& rhs)
687 -> decltype(lhs | rhs.Get())
689 return lhs | rhs.Get();
693 template <
typename LhsPortalType>
695 const typename LhsPortalType::ValueType& rhs)
696 -> decltype(lhs.Get() & rhs)
698 return lhs.Get() & rhs;
701 template <
typename LhsPortalType,
typename RhsPortalType>
703 const ArrayPortalValueReference<RhsPortalType>& rhs)
704 -> decltype(lhs.Get() & rhs.Get())
706 return lhs.Get() & rhs.Get();
709 template <
typename RhsPortalType>
711 const ArrayPortalValueReference<RhsPortalType>& rhs)
712 -> decltype(lhs & rhs.Get())
714 return lhs & rhs.Get();
718 template <
typename LhsPortalType>
720 const typename LhsPortalType::ValueType& rhs)
721 -> decltype(lhs.Get() << rhs)
723 return lhs.Get() << rhs;
726 template <
typename LhsPortalType,
typename RhsPortalType>
728 const ArrayPortalValueReference<RhsPortalType>& rhs)
729 -> decltype(lhs.Get() << rhs.Get())
731 return lhs.Get() << rhs.Get();
734 template <
typename RhsPortalType>
736 const ArrayPortalValueReference<RhsPortalType>& rhs)
737 -> decltype(lhs << rhs.Get())
739 return lhs << rhs.Get();
743 template <
typename LhsPortalType>
744 VTKM_EXEC_CONT auto operator>>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
745 const typename LhsPortalType::ValueType& rhs)
746 -> decltype(lhs.Get() >> rhs)
748 return lhs.Get() >> rhs;
751 template <
typename LhsPortalType,
typename RhsPortalType>
752 VTKM_EXEC_CONT auto operator>>(
const ArrayPortalValueReference<LhsPortalType>& lhs,
753 const ArrayPortalValueReference<RhsPortalType>& rhs)
754 -> decltype(lhs.Get() >> rhs.Get())
756 return lhs.Get() >> rhs.Get();
759 template <
typename RhsPortalType>
760 VTKM_EXEC_CONT auto operator>>(
const typename RhsPortalType::ValueType& lhs,
761 const ArrayPortalValueReference<RhsPortalType>& rhs)
762 -> decltype(lhs >> rhs.Get())
764 return lhs >> rhs.Get();
768 template <
typename PortalType>
769 VTKM_EXEC_CONT auto operator~(
const ArrayPortalValueReference<PortalType>& ref)
770 -> decltype(~ref.Get())
776 template <
typename PortalType>
777 VTKM_EXEC_CONT auto operator!(
const ArrayPortalValueReference<PortalType>& ref)
778 -> decltype(!ref.Get())
784 template <
typename LhsPortalType>
785 VTKM_EXEC_CONT auto operator&&(
const ArrayPortalValueReference<LhsPortalType>& lhs,
786 const typename LhsPortalType::ValueType& rhs)
787 -> decltype(lhs.Get() && rhs)
789 return lhs.Get() && rhs;
792 template <
typename LhsPortalType,
typename RhsPortalType>
793 VTKM_EXEC_CONT auto operator&&(
const ArrayPortalValueReference<LhsPortalType>& lhs,
794 const ArrayPortalValueReference<RhsPortalType>& rhs)
795 -> decltype(lhs.Get() && rhs.Get())
797 return lhs.Get() && rhs.Get();
800 template <
typename RhsPortalType>
801 VTKM_EXEC_CONT auto operator&&(
const typename RhsPortalType::ValueType& lhs,
802 const ArrayPortalValueReference<RhsPortalType>& rhs)
803 -> decltype(lhs && rhs.Get())
805 return lhs && rhs.Get();
809 template <
typename LhsPortalType>
810 VTKM_EXEC_CONT auto operator||(
const ArrayPortalValueReference<LhsPortalType>& lhs,
811 const typename LhsPortalType::ValueType& rhs)
812 -> decltype(lhs.Get() || rhs)
814 return lhs.Get() || rhs;
817 template <
typename LhsPortalType,
typename RhsPortalType>
818 VTKM_EXEC_CONT auto operator||(
const ArrayPortalValueReference<LhsPortalType>& lhs,
819 const ArrayPortalValueReference<RhsPortalType>& rhs)
820 -> decltype(lhs.Get() || rhs.Get())
822 return lhs.Get() || rhs.Get();
825 template <
typename RhsPortalType>
826 VTKM_EXEC_CONT auto operator||(
const typename RhsPortalType::ValueType& lhs,
827 const ArrayPortalValueReference<RhsPortalType>& rhs)
828 -> decltype(lhs || rhs.Get())
830 return lhs || rhs.Get();
841 template <
typename PortalType>
842 struct TypeTraits<
vtkm::internal::ArrayPortalValueReference<PortalType>>
843 :
vtkm::TypeTraits<typename vtkm::internal::ArrayPortalValueReference<PortalType>::ValueType>
847 template <
typename PortalType>
848 struct VecTraits<
vtkm::internal::ArrayPortalValueReference<PortalType>>
849 :
vtkm::VecTraits<typename vtkm::internal::ArrayPortalValueReference<PortalType>::ValueType>
855 #endif //vtk_m_internal_ArrayPortalValueReference_h