VTK-m  2.2
ArrayPortalValueReference.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_internal_ArrayPortalValueReference_h
11 #define vtk_m_internal_ArrayPortalValueReference_h
12 
13 #include <vtkm/TypeTraits.h>
14 #include <vtkm/Types.h>
15 #include <vtkm/VecTraits.h>
16 
17 namespace vtkm
18 {
19 namespace internal
20 {
21 
37 template <typename ArrayPortalType>
38 struct ArrayPortalValueReference
39 {
40  using ValueType = typename ArrayPortalType::ValueType;
41 
44  ArrayPortalValueReference(const ArrayPortalType& portal, vtkm::Id index)
45  : Portal(portal)
46  , Index(index)
47  {
48  }
49 
52  ArrayPortalValueReference(const ArrayPortalValueReference& ref)
53  : Portal(ref.Portal)
54  , Index(ref.Index)
55  {
56  }
57 
60  ValueType Get() const { return this->Portal.Get(this->Index); }
61 
64  operator ValueType() const { return this->Get(); }
65 
66  // Declaring Set as const seems a little weird because we are changing the value. But remember
67  // that ArrayPortalReference is only a reference class. The reference itself does not change,
68  // just the thing that it is referencing. So declaring as const is correct and necessary so that
69  // you can set the value of a reference returned from a function (which is a right hand side
70  // value).
71 
74  void Set(ValueType&& value) const { this->Portal.Set(this->Index, std::move(value)); }
75 
78  void Set(const ValueType& value) const { this->Portal.Set(this->Index, value); }
79 
80  VTKM_CONT
81  void Swap(const ArrayPortalValueReference<ArrayPortalType>& rhs) const noexcept
82  {
83  //we need use the explicit type not a proxy temp object
84  //A proxy temp object would point to the same underlying data structure
85  //and would not hold the old value of *this once *this was set to rhs.
86  const ValueType aValue = *this;
87  *this = rhs;
88  rhs = aValue;
89  }
90 
91  // Declaring operator= as const seems a little weird because we are changing the value. But
92  // remember that ArrayPortalReference is only a reference class. The reference itself does not
93  // change, just the thing that it is referencing. So declaring as const is correct and necessary
94  // so that you can set the value of a reference returned from a function (which is a right hand
95  // side value).
96 
99  const ArrayPortalValueReference<ArrayPortalType>& operator=(ValueType&& value) const
100  {
101  this->Set(std::move(value));
102  return *this;
103  }
104 
107  const ArrayPortalValueReference<ArrayPortalType>& operator=(const ValueType& value) const
108  {
109  this->Set(value);
110  return *this;
111  }
112 
113  // This special overload of the operator= is to override the behavior of the default operator=
114  // (which has the wrong behavior) with behavior consistent with the other operator= methods.
115  // It is not declared const because the default operator= is not declared const. If you try
116  // to do this assignment with a const object, you will get one of the operator= above.
118  VTKM_EXEC_CONT ArrayPortalValueReference<ArrayPortalType>& operator=(
119  const ArrayPortalValueReference<ArrayPortalType>& rhs)
120  {
121  this->Set(static_cast<ValueType>(rhs.Portal.Get(rhs.Index)));
122  return *this;
123  }
124 
126  template <typename T>
127  VTKM_EXEC_CONT ValueType operator+=(const T& rhs) const
128  {
129  ValueType lhs = this->Get();
130  lhs += rhs;
131  this->Set(lhs);
132  return lhs;
133  }
135  template <typename T>
136  VTKM_EXEC_CONT ValueType operator+=(const ArrayPortalValueReference<T>& rhs) const
137  {
138  ValueType lhs = this->Get();
139  lhs += rhs.Get();
140  this->Set(lhs);
141  return lhs;
142  }
143 
145  template <typename T>
146  VTKM_EXEC_CONT ValueType operator-=(const T& rhs) const
147  {
148  ValueType lhs = this->Get();
149  lhs -= rhs;
150  this->Set(lhs);
151  return lhs;
152  }
154  template <typename T>
155  VTKM_EXEC_CONT ValueType operator-=(const ArrayPortalValueReference<T>& rhs) const
156  {
157  ValueType lhs = this->Get();
158  lhs -= rhs.Get();
159  this->Set(lhs);
160  return lhs;
161  }
162 
164  template <typename T>
165  VTKM_EXEC_CONT ValueType operator*=(const T& rhs) const
166  {
167  ValueType lhs = this->Get();
168  lhs *= rhs;
169  this->Set(lhs);
170  return lhs;
171  }
173  template <typename T>
174  VTKM_EXEC_CONT ValueType operator*=(const ArrayPortalValueReference<T>& rhs) const
175  {
176  ValueType lhs = this->Get();
177  lhs *= rhs.Get();
178  this->Set(lhs);
179  return lhs;
180  }
181 
183  template <typename T>
184  VTKM_EXEC_CONT ValueType operator/=(const T& rhs) const
185  {
186  ValueType lhs = this->Get();
187  lhs /= rhs;
188  this->Set(lhs);
189  return lhs;
190  }
192  template <typename T>
193  VTKM_EXEC_CONT ValueType operator/=(const ArrayPortalValueReference<T>& rhs) const
194  {
195  ValueType lhs = this->Get();
196  lhs /= rhs.Get();
197  this->Set(lhs);
198  return lhs;
199  }
200 
202  template <typename T>
203  VTKM_EXEC_CONT ValueType operator%=(const T& rhs) const
204  {
205  ValueType lhs = this->Get();
206  lhs %= rhs;
207  this->Set(lhs);
208  return lhs;
209  }
211  template <typename T>
212  VTKM_EXEC_CONT ValueType operator%=(const ArrayPortalValueReference<T>& rhs) const
213  {
214  ValueType lhs = this->Get();
215  lhs %= rhs.Get();
216  this->Set(lhs);
217  return lhs;
218  }
219 
221  template <typename T>
222  VTKM_EXEC_CONT ValueType operator&=(const T& rhs) const
223  {
224  ValueType lhs = this->Get();
225  lhs &= rhs;
226  this->Set(lhs);
227  return lhs;
228  }
230  template <typename T>
231  VTKM_EXEC_CONT ValueType operator&=(const ArrayPortalValueReference<T>& rhs) const
232  {
233  ValueType lhs = this->Get();
234  lhs &= rhs.Get();
235  this->Set(lhs);
236  return lhs;
237  }
238 
240  template <typename T>
241  VTKM_EXEC_CONT ValueType operator|=(const T& rhs) const
242  {
243  ValueType lhs = this->Get();
244  lhs |= rhs;
245  this->Set(lhs);
246  return lhs;
247  }
249  template <typename T>
250  VTKM_EXEC_CONT ValueType operator|=(const ArrayPortalValueReference<T>& rhs) const
251  {
252  ValueType lhs = this->Get();
253  lhs |= rhs.Get();
254  this->Set(lhs);
255  return lhs;
256  }
257 
259  template <typename T>
260  VTKM_EXEC_CONT ValueType operator^=(const T& rhs) const
261  {
262  ValueType lhs = this->Get();
263  lhs ^= rhs;
264  this->Set(lhs);
265  return lhs;
266  }
268  template <typename T>
269  VTKM_EXEC_CONT ValueType operator^=(const ArrayPortalValueReference<T>& rhs) const
270  {
271  ValueType lhs = this->Get();
272  lhs ^= rhs.Get();
273  this->Set(lhs);
274  return lhs;
275  }
276 
278  template <typename T>
279  VTKM_EXEC_CONT ValueType operator>>=(const T& rhs) const
280  {
281  ValueType lhs = this->Get();
282  lhs >>= rhs;
283  this->Set(lhs);
284  return lhs;
285  }
287  template <typename T>
288  VTKM_EXEC_CONT ValueType operator>>=(const ArrayPortalValueReference<T>& rhs) const
289  {
290  ValueType lhs = this->Get();
291  lhs >>= rhs.Get();
292  this->Set(lhs);
293  return lhs;
294  }
295 
297  template <typename T>
298  VTKM_EXEC_CONT ValueType operator<<=(const T& rhs) const
299  {
300  ValueType lhs = this->Get();
301  lhs <<= rhs;
302  this->Set(lhs);
303  return lhs;
304  }
306  template <typename T>
307  VTKM_EXEC_CONT ValueType operator<<=(const ArrayPortalValueReference<T>& rhs) const
308  {
309  ValueType lhs = this->Get();
310  lhs <<= rhs.Get();
311  this->Set(lhs);
312  return lhs;
313  }
314 
315  // Support Vec operations so that the reference can be treated as such Vec objects. Note
316  // that although the [] operator is supported, you can only read components this way. You
317  // cannot write components one at a time.
318  VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const
319  {
321  }
323  typename vtkm::VecTraits<ValueType>::ComponentType operator[](vtkm::IdComponent index) const
324  {
325  return vtkm::VecTraits<ValueType>::GetComponent(this->Get(), index);
326  }
327 
328 private:
329  const ArrayPortalType& Portal;
330  vtkm::Id Index;
331 };
332 
333 //implement a custom swap function, since the std::swap won't work
334 //since we return RValues instead of Lvalues
335 template <typename T>
336 void swap(const vtkm::internal::ArrayPortalValueReference<T>& a,
337  const vtkm::internal::ArrayPortalValueReference<T>& b)
338 {
339  a.Swap(b);
340 }
341 
342 template <typename T>
343 void swap(const vtkm::internal::ArrayPortalValueReference<T>& a,
344  typename vtkm::internal::ArrayPortalValueReference<T>::ValueType& b)
345 {
346  using ValueType = typename vtkm::internal::ArrayPortalValueReference<T>::ValueType;
347  const ValueType tmp = a;
348  a = b;
349  b = tmp;
350 }
351 
352 template <typename T>
353 void swap(typename vtkm::internal::ArrayPortalValueReference<T>::ValueType& a,
354  const vtkm::internal::ArrayPortalValueReference<T>& b)
355 {
356  using ValueType = typename vtkm::internal::ArrayPortalValueReference<T>::ValueType;
357  const ValueType tmp = b;
358  b = a;
359  a = tmp;
360 }
361 
362 // The reason why all the operators on ArrayPortalValueReference are defined outside of the class
363 // is so that in the case that the operator in question is not defined in the value type, these
364 // operators will not be instantiated (and therefore cause a compile error) unless they are
365 // directly used (in which case a compile error is appropriate).
366 
368 template <typename LhsPortalType>
369 VTKM_EXEC_CONT auto operator==(const ArrayPortalValueReference<LhsPortalType>& lhs,
370  const typename LhsPortalType::ValueType& rhs)
371  -> decltype(lhs.Get() == rhs)
372 {
373  return lhs.Get() == rhs;
374 }
376 template <typename LhsPortalType, typename RhsPortalType>
377 VTKM_EXEC_CONT auto operator==(const ArrayPortalValueReference<LhsPortalType>& lhs,
378  const ArrayPortalValueReference<RhsPortalType>& rhs)
379  -> decltype(lhs.Get() == rhs.Get())
380 {
381  return lhs.Get() == rhs.Get();
382 }
384 template <typename RhsPortalType>
385 VTKM_EXEC_CONT auto operator==(const typename RhsPortalType::ValueType& lhs,
386  const ArrayPortalValueReference<RhsPortalType>& rhs)
387  -> decltype(lhs == rhs.Get())
388 {
389  return lhs == rhs.Get();
390 }
391 
393 template <typename LhsPortalType>
394 VTKM_EXEC_CONT auto operator!=(const ArrayPortalValueReference<LhsPortalType>& lhs,
395  const typename LhsPortalType::ValueType& rhs)
396  -> decltype(lhs.Get() != rhs)
397 {
398  return lhs.Get() != rhs;
399 }
401 template <typename LhsPortalType, typename RhsPortalType>
402 VTKM_EXEC_CONT auto operator!=(const ArrayPortalValueReference<LhsPortalType>& lhs,
403  const ArrayPortalValueReference<RhsPortalType>& rhs)
404  -> decltype(lhs.Get() != rhs.Get())
405 {
406  return lhs.Get() != rhs.Get();
407 }
409 template <typename RhsPortalType>
410 VTKM_EXEC_CONT auto operator!=(const typename RhsPortalType::ValueType& lhs,
411  const ArrayPortalValueReference<RhsPortalType>& rhs)
412  -> decltype(lhs != rhs.Get())
413 {
414  return lhs != rhs.Get();
415 }
416 
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)
422 {
423  return lhs.Get() < rhs;
424 }
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())
430 {
431  return lhs.Get() < rhs.Get();
432 }
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())
438 {
439  return lhs < rhs.Get();
440 }
441 
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)
447 {
448  return lhs.Get() > rhs;
449 }
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())
455 {
456  return lhs.Get() > rhs.Get();
457 }
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())
463 {
464  return lhs > rhs.Get();
465 }
466 
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)
472 {
473  return lhs.Get() <= rhs;
474 }
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())
480 {
481  return lhs.Get() <= rhs.Get();
482 }
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())
488 {
489  return lhs <= rhs.Get();
490 }
491 
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)
497 {
498  return lhs.Get() >= rhs;
499 }
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())
505 {
506  return lhs.Get() >= rhs.Get();
507 }
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())
513 {
514  return lhs >= rhs.Get();
515 }
516 
518 template <typename LhsPortalType>
519 VTKM_EXEC_CONT auto operator+(const ArrayPortalValueReference<LhsPortalType>& lhs,
520  const typename LhsPortalType::ValueType& rhs)
521  -> decltype(lhs.Get() + rhs)
522 {
523  return lhs.Get() + rhs;
524 }
526 template <typename LhsPortalType, typename RhsPortalType>
527 VTKM_EXEC_CONT auto operator+(const ArrayPortalValueReference<LhsPortalType>& lhs,
528  const ArrayPortalValueReference<RhsPortalType>& rhs)
529  -> decltype(lhs.Get() + rhs.Get())
530 {
531  return lhs.Get() + rhs.Get();
532 }
534 template <typename RhsPortalType>
535 VTKM_EXEC_CONT auto operator+(const typename RhsPortalType::ValueType& lhs,
536  const ArrayPortalValueReference<RhsPortalType>& rhs)
537  -> decltype(lhs + rhs.Get())
538 {
539  return lhs + rhs.Get();
540 }
541 
543 template <typename LhsPortalType>
544 VTKM_EXEC_CONT auto operator-(const ArrayPortalValueReference<LhsPortalType>& lhs,
545  const typename LhsPortalType::ValueType& rhs)
546  -> decltype(lhs.Get() - rhs)
547 {
548  return lhs.Get() - rhs;
549 }
551 template <typename LhsPortalType, typename RhsPortalType>
552 VTKM_EXEC_CONT auto operator-(const ArrayPortalValueReference<LhsPortalType>& lhs,
553  const ArrayPortalValueReference<RhsPortalType>& rhs)
554  -> decltype(lhs.Get() - rhs.Get())
555 {
556  return lhs.Get() - rhs.Get();
557 }
559 template <typename RhsPortalType>
560 VTKM_EXEC_CONT auto operator-(const typename RhsPortalType::ValueType& lhs,
561  const ArrayPortalValueReference<RhsPortalType>& rhs)
562  -> decltype(lhs - rhs.Get())
563 {
564  return lhs - rhs.Get();
565 }
566 
568 template <typename LhsPortalType>
569 VTKM_EXEC_CONT auto operator*(const ArrayPortalValueReference<LhsPortalType>& lhs,
570  const typename LhsPortalType::ValueType& rhs)
571  -> decltype(lhs.Get() * rhs)
572 {
573  return lhs.Get() * rhs;
574 }
576 template <typename LhsPortalType, typename RhsPortalType>
577 VTKM_EXEC_CONT auto operator*(const ArrayPortalValueReference<LhsPortalType>& lhs,
578  const ArrayPortalValueReference<RhsPortalType>& rhs)
579  -> decltype(lhs.Get() * rhs.Get())
580 {
581  return lhs.Get() * rhs.Get();
582 }
584 template <typename RhsPortalType>
585 VTKM_EXEC_CONT auto operator*(const typename RhsPortalType::ValueType& lhs,
586  const ArrayPortalValueReference<RhsPortalType>& rhs)
587  -> decltype(lhs * rhs.Get())
588 {
589  return lhs * rhs.Get();
590 }
591 
593 template <typename LhsPortalType>
594 VTKM_EXEC_CONT auto operator/(const ArrayPortalValueReference<LhsPortalType>& lhs,
595  const typename LhsPortalType::ValueType& rhs)
596  -> decltype(lhs.Get() / rhs)
597 {
598  return lhs.Get() / rhs;
599 }
601 template <typename LhsPortalType, typename RhsPortalType>
602 VTKM_EXEC_CONT auto operator/(const ArrayPortalValueReference<LhsPortalType>& lhs,
603  const ArrayPortalValueReference<RhsPortalType>& rhs)
604  -> decltype(lhs.Get() / rhs.Get())
605 {
606  return lhs.Get() / rhs.Get();
607 }
609 template <typename RhsPortalType>
610 VTKM_EXEC_CONT auto operator/(const typename RhsPortalType::ValueType& lhs,
611  const ArrayPortalValueReference<RhsPortalType>& rhs)
612  -> decltype(lhs / rhs.Get())
613 {
614  return lhs / rhs.Get();
615 }
616 
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)
622 {
623  return lhs.Get() % rhs;
624 }
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())
630 {
631  return lhs.Get() % rhs.Get();
632 }
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())
638 {
639  return lhs % rhs.Get();
640 }
641 
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)
647 {
648  return lhs.Get() ^ rhs;
649 }
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())
655 {
656  return lhs.Get() ^ rhs.Get();
657 }
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())
663 {
664  return lhs ^ rhs.Get();
665 }
666 
668 template <typename LhsPortalType>
669 VTKM_EXEC_CONT auto operator|(const ArrayPortalValueReference<LhsPortalType>& lhs,
670  const typename LhsPortalType::ValueType& rhs)
671  -> decltype(lhs.Get() | rhs)
672 {
673  return lhs.Get() | rhs;
674 }
676 template <typename LhsPortalType, typename RhsPortalType>
677 VTKM_EXEC_CONT auto operator|(const ArrayPortalValueReference<LhsPortalType>& lhs,
678  const ArrayPortalValueReference<RhsPortalType>& rhs)
679  -> decltype(lhs.Get() | rhs.Get())
680 {
681  return lhs.Get() | rhs.Get();
682 }
684 template <typename RhsPortalType>
685 VTKM_EXEC_CONT auto operator|(const typename RhsPortalType::ValueType& lhs,
686  const ArrayPortalValueReference<RhsPortalType>& rhs)
687  -> decltype(lhs | rhs.Get())
688 {
689  return lhs | rhs.Get();
690 }
691 
693 template <typename LhsPortalType>
694 VTKM_EXEC_CONT auto operator&(const ArrayPortalValueReference<LhsPortalType>& lhs,
695  const typename LhsPortalType::ValueType& rhs)
696  -> decltype(lhs.Get() & rhs)
697 {
698  return lhs.Get() & rhs;
699 }
701 template <typename LhsPortalType, typename RhsPortalType>
702 VTKM_EXEC_CONT auto operator&(const ArrayPortalValueReference<LhsPortalType>& lhs,
703  const ArrayPortalValueReference<RhsPortalType>& rhs)
704  -> decltype(lhs.Get() & rhs.Get())
705 {
706  return lhs.Get() & rhs.Get();
707 }
709 template <typename RhsPortalType>
710 VTKM_EXEC_CONT auto operator&(const typename RhsPortalType::ValueType& lhs,
711  const ArrayPortalValueReference<RhsPortalType>& rhs)
712  -> decltype(lhs & rhs.Get())
713 {
714  return lhs & rhs.Get();
715 }
716 
718 template <typename LhsPortalType>
719 VTKM_EXEC_CONT auto operator<<(const ArrayPortalValueReference<LhsPortalType>& lhs,
720  const typename LhsPortalType::ValueType& rhs)
721  -> decltype(lhs.Get() << rhs)
722 {
723  return lhs.Get() << rhs;
724 }
726 template <typename LhsPortalType, typename RhsPortalType>
727 VTKM_EXEC_CONT auto operator<<(const ArrayPortalValueReference<LhsPortalType>& lhs,
728  const ArrayPortalValueReference<RhsPortalType>& rhs)
729  -> decltype(lhs.Get() << rhs.Get())
730 {
731  return lhs.Get() << rhs.Get();
732 }
734 template <typename RhsPortalType>
735 VTKM_EXEC_CONT auto operator<<(const typename RhsPortalType::ValueType& lhs,
736  const ArrayPortalValueReference<RhsPortalType>& rhs)
737  -> decltype(lhs << rhs.Get())
738 {
739  return lhs << rhs.Get();
740 }
741 
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)
747 {
748  return lhs.Get() >> rhs;
749 }
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())
755 {
756  return lhs.Get() >> rhs.Get();
757 }
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())
763 {
764  return lhs >> rhs.Get();
765 }
766 
768 template <typename PortalType>
769 VTKM_EXEC_CONT auto operator~(const ArrayPortalValueReference<PortalType>& ref)
770  -> decltype(~ref.Get())
771 {
772  return ~ref.Get();
773 }
774 
776 template <typename PortalType>
777 VTKM_EXEC_CONT auto operator!(const ArrayPortalValueReference<PortalType>& ref)
778  -> decltype(!ref.Get())
779 {
780  return !ref.Get();
781 }
782 
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)
788 {
789  return lhs.Get() && rhs;
790 }
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())
796 {
797  return lhs.Get() && rhs.Get();
798 }
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())
804 {
805  return lhs && rhs.Get();
806 }
807 
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)
813 {
814  return lhs.Get() || rhs;
815 }
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())
821 {
822  return lhs.Get() || rhs.Get();
823 }
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())
829 {
830  return lhs || rhs.Get();
831 }
832 }
833 } // namespace vtkm::internal
834 
835 namespace vtkm
836 {
837 
838 // Make specialization for TypeTraits and VecTraits so that the reference
839 // behaves the same as the value.
840 
841 template <typename PortalType>
842 struct TypeTraits<vtkm::internal::ArrayPortalValueReference<PortalType>>
843  : vtkm::TypeTraits<typename vtkm::internal::ArrayPortalValueReference<PortalType>::ValueType>
844 {
845 };
846 
847 template <typename PortalType>
848 struct VecTraits<vtkm::internal::ArrayPortalValueReference<PortalType>>
849  : vtkm::VecTraits<typename vtkm::internal::ArrayPortalValueReference<PortalType>::ValueType>
850 {
851 };
852 
853 } // namespace vtkm
854 
855 #endif //vtk_m_internal_ArrayPortalValueReference_h
vtkm::operator!=
bool operator!=(const vtkm::Matrix< T, NumRow, NumCol > &a, const vtkm::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:631
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in VTKm (an...
Definition: TypeTraits.h:61
vtkm::Get
auto Get(const vtkm::Tuple< Ts... > &tuple)
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:81
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::operator/
VTKM_EXEC_CONT vtkm::Vec< T, Size > operator/(vtkm::Vec< T, Size > a, const vtkm::Vec< T, Size > &b)
Definition: VecOperators.h:371
vtkm::operator<<
std::ostream & operator<<(std::ostream &stream, const vtkm::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:248
vtkm::VecTraits::ComponentType
T ComponentType
Type of the components in the vector.
Definition: VecTraits.h:71
vtkm::operator*
VTKM_EXEC_CONT vtkm::Vec< T, Size > operator*(vtkm::Vec< T, Size > a, const vtkm::Vec< T, Size > &b)
Definition: VecOperators.h:185
vtkm::operator==
bool operator==(const vtkm::Matrix< T, NumRow, NumCol > &a, const vtkm::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:617
vtkm::operator+
VTKM_EXEC_CONT vtkm::Vec< T, Size > operator+(vtkm::Vec< T, Size > a, const vtkm::Vec< T, Size > &b)
Definition: VecOperators.h:92
TypeTraits.h
vtkm::operator-
VTKM_EXEC_CONT std::enable_if<(std::is_floating_point< T >::value||std::is_signed< T >::value), vtkm::Vec< T, Size > >::type operator-(vtkm::Vec< T, Size > x)
Definition: VecOperators.h:41
vtkm::VecTraits::GetNumberOfComponents
static constexpr vtkm::IdComponent GetNumberOfComponents(const T &)
Returns the number of components in the given vector.
Definition: VecTraits.h:94
Index
int Index
Definition: ChooseCudaDevice.h:87
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::VecTraits::GetComponent
static const ComponentType & GetComponent(const T &vector, vtkm::IdComponent)
Returns the value in a given component of the vector.
Definition: VecTraits.h:117
vtkm::cont::operator|
InitializeOptions operator|(const InitializeOptions &lhs, const InitializeOptions &rhs)
Definition: Initialize.h:76
vtkm::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:61
vtkm::cont::operator&
InitializeOptions operator&(const InitializeOptions &lhs, const InitializeOptions &rhs)
Definition: Initialize.h:81
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
VecTraits.h
vtkm::Swap
void Swap(T &a, T &b)
Performs a swap operation. Safe to call from cuda code.
Definition: Swap.h:59