Viskores  1.0
ArrayPortalValueReference.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_internal_ArrayPortalValueReference_h
19 #define viskores_internal_ArrayPortalValueReference_h
20 
21 #include <viskores/TypeTraits.h>
22 #include <viskores/Types.h>
23 #include <viskores/VecTraits.h>
24 
25 namespace viskores
26 {
27 namespace internal
28 {
29 
45 template <typename ArrayPortalType>
46 struct ArrayPortalValueReference
47 {
48  using ValueType = typename ArrayPortalType::ValueType;
49 
52  ArrayPortalValueReference(const ArrayPortalType& portal, viskores::Id index)
53  : Portal(portal)
54  , Index(index)
55  {
56  }
57 
60  ArrayPortalValueReference(const ArrayPortalValueReference& ref)
61  : Portal(ref.Portal)
62  , Index(ref.Index)
63  {
64  }
65 
68  ValueType Get() const { return this->Portal.Get(this->Index); }
69 
72  operator ValueType() const { return this->Get(); }
73 
74  // Declaring Set as const seems a little weird because we are changing the value. But remember
75  // that ArrayPortalReference is only a reference class. The reference itself does not change,
76  // just the thing that it is referencing. So declaring as const is correct and necessary so that
77  // you can set the value of a reference returned from a function (which is a right hand side
78  // value).
79 
82  void Set(ValueType&& value) const { this->Portal.Set(this->Index, std::move(value)); }
83 
86  void Set(const ValueType& value) const { this->Portal.Set(this->Index, value); }
87 
89  void Swap(const ArrayPortalValueReference<ArrayPortalType>& rhs) const noexcept
90  {
91  //we need use the explicit type not a proxy temp object
92  //A proxy temp object would point to the same underlying data structure
93  //and would not hold the old value of *this once *this was set to rhs.
94  const ValueType aValue = *this;
95  *this = rhs;
96  rhs = aValue;
97  }
98 
99  // Declaring operator= as const seems a little weird because we are changing the value. But
100  // remember that ArrayPortalReference is only a reference class. The reference itself does not
101  // change, just the thing that it is referencing. So declaring as const is correct and necessary
102  // so that you can set the value of a reference returned from a function (which is a right hand
103  // side value).
104 
107  const ArrayPortalValueReference<ArrayPortalType>& operator=(ValueType&& value) const
108  {
109  this->Set(std::move(value));
110  return *this;
111  }
112 
115  const ArrayPortalValueReference<ArrayPortalType>& operator=(const ValueType& value) const
116  {
117  this->Set(value);
118  return *this;
119  }
120 
121  // This special overload of the operator= is to override the behavior of the default operator=
122  // (which has the wrong behavior) with behavior consistent with the other operator= methods.
123  // It is not declared const because the default operator= is not declared const. If you try
124  // to do this assignment with a const object, you will get one of the operator= above.
126  VISKORES_EXEC_CONT ArrayPortalValueReference<ArrayPortalType>& operator=(
127  const ArrayPortalValueReference<ArrayPortalType>& rhs)
128  {
129  this->Set(static_cast<ValueType>(rhs.Portal.Get(rhs.Index)));
130  return *this;
131  }
132 
134  template <typename T>
135  VISKORES_EXEC_CONT ValueType operator+=(const T& rhs) const
136  {
137  ValueType lhs = this->Get();
138  lhs += rhs;
139  this->Set(lhs);
140  return lhs;
141  }
143  template <typename T>
144  VISKORES_EXEC_CONT ValueType operator+=(const ArrayPortalValueReference<T>& rhs) const
145  {
146  ValueType lhs = this->Get();
147  lhs += rhs.Get();
148  this->Set(lhs);
149  return lhs;
150  }
151 
153  template <typename T>
154  VISKORES_EXEC_CONT ValueType operator-=(const T& rhs) const
155  {
156  ValueType lhs = this->Get();
157  lhs -= rhs;
158  this->Set(lhs);
159  return lhs;
160  }
162  template <typename T>
163  VISKORES_EXEC_CONT ValueType operator-=(const ArrayPortalValueReference<T>& rhs) const
164  {
165  ValueType lhs = this->Get();
166  lhs -= rhs.Get();
167  this->Set(lhs);
168  return lhs;
169  }
170 
172  template <typename T>
173  VISKORES_EXEC_CONT ValueType operator*=(const T& rhs) const
174  {
175  ValueType lhs = this->Get();
176  lhs *= rhs;
177  this->Set(lhs);
178  return lhs;
179  }
181  template <typename T>
182  VISKORES_EXEC_CONT ValueType operator*=(const ArrayPortalValueReference<T>& rhs) const
183  {
184  ValueType lhs = this->Get();
185  lhs *= rhs.Get();
186  this->Set(lhs);
187  return lhs;
188  }
189 
191  template <typename T>
192  VISKORES_EXEC_CONT ValueType operator/=(const T& rhs) const
193  {
194  ValueType lhs = this->Get();
195  lhs /= rhs;
196  this->Set(lhs);
197  return lhs;
198  }
200  template <typename T>
201  VISKORES_EXEC_CONT ValueType operator/=(const ArrayPortalValueReference<T>& rhs) const
202  {
203  ValueType lhs = this->Get();
204  lhs /= rhs.Get();
205  this->Set(lhs);
206  return lhs;
207  }
208 
210  template <typename T>
211  VISKORES_EXEC_CONT ValueType operator%=(const T& rhs) const
212  {
213  ValueType lhs = this->Get();
214  lhs %= rhs;
215  this->Set(lhs);
216  return lhs;
217  }
219  template <typename T>
220  VISKORES_EXEC_CONT ValueType operator%=(const ArrayPortalValueReference<T>& rhs) const
221  {
222  ValueType lhs = this->Get();
223  lhs %= rhs.Get();
224  this->Set(lhs);
225  return lhs;
226  }
227 
229  template <typename T>
230  VISKORES_EXEC_CONT ValueType operator&=(const T& rhs) const
231  {
232  ValueType lhs = this->Get();
233  lhs &= rhs;
234  this->Set(lhs);
235  return lhs;
236  }
238  template <typename T>
239  VISKORES_EXEC_CONT ValueType operator&=(const ArrayPortalValueReference<T>& rhs) const
240  {
241  ValueType lhs = this->Get();
242  lhs &= rhs.Get();
243  this->Set(lhs);
244  return lhs;
245  }
246 
248  template <typename T>
249  VISKORES_EXEC_CONT ValueType operator|=(const T& rhs) const
250  {
251  ValueType lhs = this->Get();
252  lhs |= rhs;
253  this->Set(lhs);
254  return lhs;
255  }
257  template <typename T>
258  VISKORES_EXEC_CONT ValueType operator|=(const ArrayPortalValueReference<T>& rhs) const
259  {
260  ValueType lhs = this->Get();
261  lhs |= rhs.Get();
262  this->Set(lhs);
263  return lhs;
264  }
265 
267  template <typename T>
268  VISKORES_EXEC_CONT ValueType operator^=(const T& rhs) const
269  {
270  ValueType lhs = this->Get();
271  lhs ^= rhs;
272  this->Set(lhs);
273  return lhs;
274  }
276  template <typename T>
277  VISKORES_EXEC_CONT ValueType operator^=(const ArrayPortalValueReference<T>& rhs) const
278  {
279  ValueType lhs = this->Get();
280  lhs ^= rhs.Get();
281  this->Set(lhs);
282  return lhs;
283  }
284 
286  template <typename T>
287  VISKORES_EXEC_CONT ValueType operator>>=(const T& rhs) const
288  {
289  ValueType lhs = this->Get();
290  lhs >>= rhs;
291  this->Set(lhs);
292  return lhs;
293  }
295  template <typename T>
296  VISKORES_EXEC_CONT ValueType operator>>=(const ArrayPortalValueReference<T>& rhs) const
297  {
298  ValueType lhs = this->Get();
299  lhs >>= rhs.Get();
300  this->Set(lhs);
301  return lhs;
302  }
303 
305  template <typename T>
306  VISKORES_EXEC_CONT ValueType operator<<=(const T& rhs) const
307  {
308  ValueType lhs = this->Get();
309  lhs <<= rhs;
310  this->Set(lhs);
311  return lhs;
312  }
314  template <typename T>
315  VISKORES_EXEC_CONT ValueType operator<<=(const ArrayPortalValueReference<T>& rhs) const
316  {
317  ValueType lhs = this->Get();
318  lhs <<= rhs.Get();
319  this->Set(lhs);
320  return lhs;
321  }
322 
323  // Support Vec operations so that the reference can be treated as such Vec objects. Note
324  // that although the [] operator is supported, you can only read components this way. You
325  // cannot write components one at a time.
326  VISKORES_EXEC_CONT viskores::IdComponent GetNumberOfComponents() const
327  {
329  }
332  viskores::IdComponent index) const
333  {
334  return viskores::VecTraits<ValueType>::GetComponent(this->Get(), index);
335  }
336 
337 private:
338  const ArrayPortalType& Portal;
340 };
341 
342 //implement a custom swap function, since the std::swap won't work
343 //since we return RValues instead of Lvalues
344 template <typename T>
345 void swap(const viskores::internal::ArrayPortalValueReference<T>& a,
346  const viskores::internal::ArrayPortalValueReference<T>& b)
347 {
348  a.Swap(b);
349 }
350 
351 template <typename T>
352 void swap(const viskores::internal::ArrayPortalValueReference<T>& a,
353  typename viskores::internal::ArrayPortalValueReference<T>::ValueType& b)
354 {
355  using ValueType = typename viskores::internal::ArrayPortalValueReference<T>::ValueType;
356  const ValueType tmp = a;
357  a = b;
358  b = tmp;
359 }
360 
361 template <typename T>
362 void swap(typename viskores::internal::ArrayPortalValueReference<T>::ValueType& a,
363  const viskores::internal::ArrayPortalValueReference<T>& b)
364 {
365  using ValueType = typename viskores::internal::ArrayPortalValueReference<T>::ValueType;
366  const ValueType tmp = b;
367  b = a;
368  a = tmp;
369 }
370 
371 // The reason why all the operators on ArrayPortalValueReference are defined outside of the class
372 // is so that in the case that the operator in question is not defined in the value type, these
373 // operators will not be instantiated (and therefore cause a compile error) unless they are
374 // directly used (in which case a compile error is appropriate).
375 
377 template <typename LhsPortalType>
378 VISKORES_EXEC_CONT auto operator==(const ArrayPortalValueReference<LhsPortalType>& lhs,
379  const typename LhsPortalType::ValueType& rhs)
380  -> decltype(lhs.Get() == rhs)
381 {
382  return lhs.Get() == rhs;
383 }
385 template <typename LhsPortalType, typename RhsPortalType>
386 VISKORES_EXEC_CONT auto operator==(const ArrayPortalValueReference<LhsPortalType>& lhs,
387  const ArrayPortalValueReference<RhsPortalType>& rhs)
388  -> decltype(lhs.Get() == rhs.Get())
389 {
390  return lhs.Get() == rhs.Get();
391 }
393 template <typename RhsPortalType>
394 VISKORES_EXEC_CONT auto operator==(const typename RhsPortalType::ValueType& lhs,
395  const ArrayPortalValueReference<RhsPortalType>& rhs)
396  -> decltype(lhs == rhs.Get())
397 {
398  return lhs == rhs.Get();
399 }
400 
402 template <typename LhsPortalType>
403 VISKORES_EXEC_CONT auto operator!=(const ArrayPortalValueReference<LhsPortalType>& lhs,
404  const typename LhsPortalType::ValueType& rhs)
405  -> decltype(lhs.Get() != rhs)
406 {
407  return lhs.Get() != rhs;
408 }
410 template <typename LhsPortalType, typename RhsPortalType>
411 VISKORES_EXEC_CONT auto operator!=(const ArrayPortalValueReference<LhsPortalType>& lhs,
412  const ArrayPortalValueReference<RhsPortalType>& rhs)
413  -> decltype(lhs.Get() != rhs.Get())
414 {
415  return lhs.Get() != rhs.Get();
416 }
418 template <typename RhsPortalType>
419 VISKORES_EXEC_CONT auto operator!=(const typename RhsPortalType::ValueType& lhs,
420  const ArrayPortalValueReference<RhsPortalType>& rhs)
421  -> decltype(lhs != rhs.Get())
422 {
423  return lhs != rhs.Get();
424 }
425 
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)
431 {
432  return lhs.Get() < rhs;
433 }
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())
439 {
440  return lhs.Get() < rhs.Get();
441 }
443 template <typename RhsPortalType>
444 VISKORES_EXEC_CONT auto operator<(const typename RhsPortalType::ValueType& lhs,
445  const ArrayPortalValueReference<RhsPortalType>& rhs)
446  -> decltype(lhs < rhs.Get())
447 {
448  return lhs < rhs.Get();
449 }
450 
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)
456 {
457  return lhs.Get() > rhs;
458 }
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())
464 {
465  return lhs.Get() > rhs.Get();
466 }
468 template <typename RhsPortalType>
469 VISKORES_EXEC_CONT auto operator>(const typename RhsPortalType::ValueType& lhs,
470  const ArrayPortalValueReference<RhsPortalType>& rhs)
471  -> decltype(lhs > rhs.Get())
472 {
473  return lhs > rhs.Get();
474 }
475 
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)
481 {
482  return lhs.Get() <= rhs;
483 }
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())
489 {
490  return lhs.Get() <= rhs.Get();
491 }
493 template <typename RhsPortalType>
494 VISKORES_EXEC_CONT auto operator<=(const typename RhsPortalType::ValueType& lhs,
495  const ArrayPortalValueReference<RhsPortalType>& rhs)
496  -> decltype(lhs <= rhs.Get())
497 {
498  return lhs <= rhs.Get();
499 }
500 
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)
506 {
507  return lhs.Get() >= rhs;
508 }
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())
514 {
515  return lhs.Get() >= rhs.Get();
516 }
518 template <typename RhsPortalType>
519 VISKORES_EXEC_CONT auto operator>=(const typename RhsPortalType::ValueType& lhs,
520  const ArrayPortalValueReference<RhsPortalType>& rhs)
521  -> decltype(lhs >= rhs.Get())
522 {
523  return lhs >= rhs.Get();
524 }
525 
527 template <typename LhsPortalType>
528 VISKORES_EXEC_CONT auto operator+(const ArrayPortalValueReference<LhsPortalType>& lhs,
529  const typename LhsPortalType::ValueType& rhs)
530  -> decltype(lhs.Get() + rhs)
531 {
532  return lhs.Get() + rhs;
533 }
535 template <typename LhsPortalType, typename RhsPortalType>
536 VISKORES_EXEC_CONT auto operator+(const ArrayPortalValueReference<LhsPortalType>& lhs,
537  const ArrayPortalValueReference<RhsPortalType>& rhs)
538  -> decltype(lhs.Get() + rhs.Get())
539 {
540  return lhs.Get() + rhs.Get();
541 }
543 template <typename RhsPortalType>
544 VISKORES_EXEC_CONT auto operator+(const typename RhsPortalType::ValueType& lhs,
545  const ArrayPortalValueReference<RhsPortalType>& rhs)
546  -> decltype(lhs + rhs.Get())
547 {
548  return lhs + rhs.Get();
549 }
550 
552 template <typename LhsPortalType>
553 VISKORES_EXEC_CONT auto operator-(const ArrayPortalValueReference<LhsPortalType>& lhs,
554  const typename LhsPortalType::ValueType& rhs)
555  -> decltype(lhs.Get() - rhs)
556 {
557  return lhs.Get() - rhs;
558 }
560 template <typename LhsPortalType, typename RhsPortalType>
561 VISKORES_EXEC_CONT auto operator-(const ArrayPortalValueReference<LhsPortalType>& lhs,
562  const ArrayPortalValueReference<RhsPortalType>& rhs)
563  -> decltype(lhs.Get() - rhs.Get())
564 {
565  return lhs.Get() - rhs.Get();
566 }
568 template <typename RhsPortalType>
569 VISKORES_EXEC_CONT auto operator-(const typename RhsPortalType::ValueType& lhs,
570  const ArrayPortalValueReference<RhsPortalType>& rhs)
571  -> decltype(lhs - rhs.Get())
572 {
573  return lhs - rhs.Get();
574 }
575 
577 template <typename LhsPortalType>
578 VISKORES_EXEC_CONT auto operator*(const ArrayPortalValueReference<LhsPortalType>& lhs,
579  const typename LhsPortalType::ValueType& rhs)
580  -> decltype(lhs.Get() * rhs)
581 {
582  return lhs.Get() * rhs;
583 }
585 template <typename LhsPortalType, typename RhsPortalType>
586 VISKORES_EXEC_CONT auto operator*(const ArrayPortalValueReference<LhsPortalType>& lhs,
587  const ArrayPortalValueReference<RhsPortalType>& rhs)
588  -> decltype(lhs.Get() * rhs.Get())
589 {
590  return lhs.Get() * rhs.Get();
591 }
593 template <typename RhsPortalType>
594 VISKORES_EXEC_CONT auto operator*(const typename RhsPortalType::ValueType& lhs,
595  const ArrayPortalValueReference<RhsPortalType>& rhs)
596  -> decltype(lhs * rhs.Get())
597 {
598  return lhs * rhs.Get();
599 }
600 
602 template <typename LhsPortalType>
603 VISKORES_EXEC_CONT auto operator/(const ArrayPortalValueReference<LhsPortalType>& lhs,
604  const typename LhsPortalType::ValueType& rhs)
605  -> decltype(lhs.Get() / rhs)
606 {
607  return lhs.Get() / rhs;
608 }
610 template <typename LhsPortalType, typename RhsPortalType>
611 VISKORES_EXEC_CONT auto operator/(const ArrayPortalValueReference<LhsPortalType>& lhs,
612  const ArrayPortalValueReference<RhsPortalType>& rhs)
613  -> decltype(lhs.Get() / rhs.Get())
614 {
615  return lhs.Get() / rhs.Get();
616 }
618 template <typename RhsPortalType>
619 VISKORES_EXEC_CONT auto operator/(const typename RhsPortalType::ValueType& lhs,
620  const ArrayPortalValueReference<RhsPortalType>& rhs)
621  -> decltype(lhs / rhs.Get())
622 {
623  return lhs / rhs.Get();
624 }
625 
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)
631 {
632  return lhs.Get() % rhs;
633 }
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())
639 {
640  return lhs.Get() % rhs.Get();
641 }
643 template <typename RhsPortalType>
644 VISKORES_EXEC_CONT auto operator%(const typename RhsPortalType::ValueType& lhs,
645  const ArrayPortalValueReference<RhsPortalType>& rhs)
646  -> decltype(lhs % rhs.Get())
647 {
648  return lhs % rhs.Get();
649 }
650 
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)
656 {
657  return lhs.Get() ^ rhs;
658 }
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())
664 {
665  return lhs.Get() ^ rhs.Get();
666 }
668 template <typename RhsPortalType>
669 VISKORES_EXEC_CONT auto operator^(const typename RhsPortalType::ValueType& lhs,
670  const ArrayPortalValueReference<RhsPortalType>& rhs)
671  -> decltype(lhs ^ rhs.Get())
672 {
673  return lhs ^ rhs.Get();
674 }
675 
677 template <typename LhsPortalType>
678 VISKORES_EXEC_CONT auto operator|(const ArrayPortalValueReference<LhsPortalType>& lhs,
679  const typename LhsPortalType::ValueType& rhs)
680  -> decltype(lhs.Get() | rhs)
681 {
682  return lhs.Get() | rhs;
683 }
685 template <typename LhsPortalType, typename RhsPortalType>
686 VISKORES_EXEC_CONT auto operator|(const ArrayPortalValueReference<LhsPortalType>& lhs,
687  const ArrayPortalValueReference<RhsPortalType>& rhs)
688  -> decltype(lhs.Get() | rhs.Get())
689 {
690  return lhs.Get() | rhs.Get();
691 }
693 template <typename RhsPortalType>
694 VISKORES_EXEC_CONT auto operator|(const typename RhsPortalType::ValueType& lhs,
695  const ArrayPortalValueReference<RhsPortalType>& rhs)
696  -> decltype(lhs | rhs.Get())
697 {
698  return lhs | rhs.Get();
699 }
700 
702 template <typename LhsPortalType>
703 VISKORES_EXEC_CONT auto operator&(const ArrayPortalValueReference<LhsPortalType>& lhs,
704  const typename LhsPortalType::ValueType& rhs)
705  -> decltype(lhs.Get() & rhs)
706 {
707  return lhs.Get() & rhs;
708 }
710 template <typename LhsPortalType, typename RhsPortalType>
711 VISKORES_EXEC_CONT auto operator&(const ArrayPortalValueReference<LhsPortalType>& lhs,
712  const ArrayPortalValueReference<RhsPortalType>& rhs)
713  -> decltype(lhs.Get() & rhs.Get())
714 {
715  return lhs.Get() & rhs.Get();
716 }
718 template <typename RhsPortalType>
719 VISKORES_EXEC_CONT auto operator&(const typename RhsPortalType::ValueType& lhs,
720  const ArrayPortalValueReference<RhsPortalType>& rhs)
721  -> decltype(lhs & rhs.Get())
722 {
723  return lhs & rhs.Get();
724 }
725 
727 template <typename LhsPortalType>
728 VISKORES_EXEC_CONT auto operator<<(const ArrayPortalValueReference<LhsPortalType>& lhs,
729  const typename LhsPortalType::ValueType& rhs)
730  -> decltype(lhs.Get() << rhs)
731 {
732  return lhs.Get() << rhs;
733 }
735 template <typename LhsPortalType, typename RhsPortalType>
736 VISKORES_EXEC_CONT auto operator<<(const ArrayPortalValueReference<LhsPortalType>& lhs,
737  const ArrayPortalValueReference<RhsPortalType>& rhs)
738  -> decltype(lhs.Get() << rhs.Get())
739 {
740  return lhs.Get() << rhs.Get();
741 }
743 template <typename RhsPortalType>
744 VISKORES_EXEC_CONT auto operator<<(const typename RhsPortalType::ValueType& lhs,
745  const ArrayPortalValueReference<RhsPortalType>& rhs)
746  -> decltype(lhs << rhs.Get())
747 {
748  return lhs << rhs.Get();
749 }
750 
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)
756 {
757  return lhs.Get() >> rhs;
758 }
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())
764 {
765  return lhs.Get() >> rhs.Get();
766 }
768 template <typename RhsPortalType>
769 VISKORES_EXEC_CONT auto operator>>(const typename RhsPortalType::ValueType& lhs,
770  const ArrayPortalValueReference<RhsPortalType>& rhs)
771  -> decltype(lhs >> rhs.Get())
772 {
773  return lhs >> rhs.Get();
774 }
775 
777 template <typename PortalType>
778 VISKORES_EXEC_CONT auto operator~(const ArrayPortalValueReference<PortalType>& ref)
779  -> decltype(~ref.Get())
780 {
781  return ~ref.Get();
782 }
783 
785 template <typename PortalType>
786 VISKORES_EXEC_CONT auto operator!(const ArrayPortalValueReference<PortalType>& ref)
787  -> decltype(!ref.Get())
788 {
789  return !ref.Get();
790 }
791 
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)
797 {
798  return lhs.Get() && rhs;
799 }
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())
805 {
806  return lhs.Get() && rhs.Get();
807 }
809 template <typename RhsPortalType>
810 VISKORES_EXEC_CONT auto operator&&(const typename RhsPortalType::ValueType& lhs,
811  const ArrayPortalValueReference<RhsPortalType>& rhs)
812  -> decltype(lhs && rhs.Get())
813 {
814  return lhs && rhs.Get();
815 }
816 
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)
822 {
823  return lhs.Get() || rhs;
824 }
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())
830 {
831  return lhs.Get() || rhs.Get();
832 }
834 template <typename RhsPortalType>
835 VISKORES_EXEC_CONT auto operator||(const typename RhsPortalType::ValueType& lhs,
836  const ArrayPortalValueReference<RhsPortalType>& rhs)
837  -> decltype(lhs || rhs.Get())
838 {
839  return lhs || rhs.Get();
840 }
841 }
842 } // namespace viskores::internal
843 
844 namespace viskores
845 {
846 
847 // Make specialization for TypeTraits and VecTraits so that the reference
848 // behaves the same as the value.
849 
850 template <typename PortalType>
851 struct TypeTraits<viskores::internal::ArrayPortalValueReference<PortalType>>
853  typename viskores::internal::ArrayPortalValueReference<PortalType>::ValueType>
854 {
855 };
856 
857 template <typename PortalType>
858 struct VecTraits<viskores::internal::ArrayPortalValueReference<PortalType>>
860  typename viskores::internal::ArrayPortalValueReference<PortalType>::ValueType>
861 {
862 };
863 
864 } // namespace viskores
865 
866 #endif //viskores_internal_ArrayPortalValueReference_h
viskores::operator/
VISKORES_EXEC_CONT viskores::Vec< T, Size > operator/(viskores::Vec< T, Size > a, const viskores::Vec< T, Size > &b)
Definition: VecOperators.h:379
viskores::operator==
bool operator==(const viskores::Matrix< T, NumRow, NumCol > &a, const viskores::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:632
Types.h
VISKORES_SUPPRESS_EXEC_WARNINGS
#define VISKORES_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:61
viskores::operator+
VISKORES_EXEC_CONT viskores::Vec< T, Size > operator+(viskores::Vec< T, Size > a, const viskores::Vec< T, Size > &b)
Definition: VecOperators.h:100
viskores::operator*
VISKORES_EXEC_CONT viskores::Vec< T, Size > operator*(viskores::Vec< T, Size > a, const viskores::Vec< T, Size > &b)
Definition: VecOperators.h:193
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::VecTraits::GetComponent
static const ComponentType & GetComponent(const T &vector, viskores::IdComponent)
Returns the value in a given component of the vector.
Definition: VecTraits.h:125
TypeTraits.h
viskores::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in Viskores...
Definition: TypeTraits.h:69
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::operator<<
std::ostream & operator<<(std::ostream &stream, const viskores::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:268
viskores::VecTraits::GetNumberOfComponents
static constexpr viskores::IdComponent GetNumberOfComponents(const T &)
Returns the number of components in the given vector.
Definition: VecTraits.h:102
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::operator|
InitializeOptions operator|(const InitializeOptions &lhs, const InitializeOptions &rhs)
Definition: Initialize.h:84
viskores::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:69
Index
int Index
Definition: ChooseCudaDevice.h:95
viskores::operator-
VISKORES_EXEC_CONT std::enable_if<(std::is_floating_point< T >::value||std::is_signed< T >::value), viskores::Vec< T, Size > >::type operator-(viskores::Vec< T, Size > x)
Definition: VecOperators.h:49
viskores::Swap
void Swap(T &a, T &b)
Performs a swap operation. Safe to call from cuda code.
Definition: Swap.h:71
viskores::VecTraits::ComponentType
T ComponentType
Type of the components in the vector.
Definition: VecTraits.h:79
viskores::operator!=
bool operator!=(const viskores::Matrix< T, NumRow, NumCol > &a, const viskores::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:646
viskores::Get
auto Get(const viskores::Tuple< Ts... > &tuple)
Retrieve the object from a viskores::Tuple at the given index.
Definition: Tuple.h:89
viskores::cont::operator&
InitializeOptions operator&(const InitializeOptions &lhs, const InitializeOptions &rhs)
Definition: Initialize.h:89
VecTraits.h