//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. // // Copyright 2014 Sandia Corporation. // Copyright 2014 UT-Battelle, LLC. // Copyright 2014 Los Alamos National Security. // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. // // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ #ifndef vtk_m_Pair_h #define vtk_m_Pair_h #include #include #include #include namespace vtkm { /// A \c vtkm::Pair is essentially the same as an STL pair object except that /// the methods (constructors and operators) are defined to work in both the /// control and execution environments (whereas std::pair is likely to work /// only in the control environment). /// template struct Pair { /// The type of the first object. /// typedef T1 FirstType; /// The type of the second object. /// typedef T2 SecondType; /// The same as FirstType, but follows the naming convention of std::pair. /// typedef FirstType first_type; /// The same as SecondType, but follows the naming convention of std::pair. /// typedef SecondType second_type; /// The pair's first object. Note that this field breaks VTK-m's naming /// conventions to make vtkm::Pair more compatible with std::pair. /// FirstType first; /// The pair's second object. Note that this field breaks VTK-m's naming /// conventions to make vtkm::Pair more compatible with std::pair. /// SecondType second; VTKM_EXEC_CONT Pair() : first(), second() { } VTKM_EXEC_CONT Pair(const FirstType &firstSrc, const SecondType &secondSrc) : first(firstSrc), second(secondSrc) { } template VTKM_EXEC_CONT Pair(const vtkm::Pair &src) : first(src.first), second(src.second) { } template VTKM_EXEC_CONT Pair(const std::pair &src) : first(src.first), second(src.second) { } VTKM_EXEC_CONT vtkm::Pair & operator=(const vtkm::Pair &src) { this->first = src.first; this->second = src.second; return *this; } VTKM_EXEC_CONT bool operator==(const vtkm::Pair &other) const { return ((this->first == other.first) && (this->second == other.second)); } VTKM_EXEC_CONT bool operator!=(const vtkm::Pair &other) const { return !(*this == other); } /// Tests ordering on the first object, and then on the second object if the /// first are equal. /// VTKM_EXEC_CONT bool operator<(const vtkm::Pair &other) const { return ((this->first < other.first) || (!(other.first < this->first) && (this->second < other.second))); } /// Tests ordering on the first object, and then on the second object if the /// first are equal. /// VTKM_EXEC_CONT bool operator>(const vtkm::Pair &other) const { return (other < *this); } /// Tests ordering on the first object, and then on the second object if the /// first are equal. /// VTKM_EXEC_CONT bool operator<=(const vtkm::Pair &other) const { return !(other < *this); } /// Tests ordering on the first object, and then on the second object if the /// first are equal. /// VTKM_EXEC_CONT bool operator>=(const vtkm::Pair &other) const { return !(*this < other); } }; /// Pairwise Add. /// This is done by adding the two objects separately. /// Useful for Reduce operation on a zipped array template VTKM_EXEC_CONT vtkm::Pair operator+(const vtkm::Pair& a, const vtkm::Pair &b) { return vtkm::Pair(a.first + b.first, a.second + b.second); } template VTKM_EXEC_CONT vtkm::Pair make_Pair(const T1 &firstSrc, const T2 &secondSrc) { return vtkm::Pair(firstSrc, secondSrc); } } // namespace vtkm #endif //vtk_m_Pair_h