SpECTRE Documentation Coverage Report
Current view: top level - DataStructures - IdPair.hpp Hit Total Coverage
Commit: 9b01d30df5d2e946e7e38cc43c008be18ae9b1d2 Lines: 1 5 20.0 %
Date: 2024-04-23 04:54:49
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include <ostream>
       7             : #include <pup.h>
       8             : #include <type_traits>
       9             : #include <utility>
      10             : 
      11             : /*!
      12             :  * \ingroup DataStructuresGroup
      13             :  * \brief A data structure that contains an ID and data associated with that ID.
      14             :  */
      15             : template <typename IdType, typename DataType>
      16           1 : struct IdPair {
      17           0 :   IdType id{};
      18           0 :   DataType data{};
      19             : };
      20             : 
      21             : template <typename IdType, typename DataType>
      22           0 : IdPair<std::decay_t<IdType>, std::decay_t<DataType>> make_id_pair(
      23             :     IdType&& id, DataType&& data) {
      24             :   return {std::forward<IdType>(id), std::forward<DataType>(data)};
      25             : }
      26             : 
      27             : /// \cond
      28             : // We write the pup function as a free function to keep IdPair a POD
      29             : // clang-tidy: no non-const references
      30             : template <typename IdType, typename DataType>
      31             : void pup(PUP::er& p, IdPair<IdType, DataType>& t) {  // NOLINT
      32             :   p | t.id;
      33             :   p | t.data;
      34             : }
      35             : 
      36             : // clang-tidy: no non-const references
      37             : template <typename IdType, typename DataType>
      38             : void operator|(PUP::er& p, IdPair<IdType, DataType>& t) {  // NOLINT
      39             :   pup(p, t);
      40             : }
      41             : 
      42             : template <typename IdType, typename DataType>
      43             : bool operator==(const IdPair<IdType, DataType>& lhs,
      44             :                 const IdPair<IdType, DataType>& rhs) {
      45             :   return lhs.id == rhs.id and lhs.data == rhs.data;
      46             : }
      47             : 
      48             : template <typename IdType, typename DataType>
      49             : bool operator!=(const IdPair<IdType, DataType>& lhs,
      50             :                 const IdPair<IdType, DataType>& rhs) {
      51             :   return not(lhs == rhs);
      52             : }
      53             : 
      54             : template <typename IdType, typename DataType>
      55             : std::ostream& operator<<(std::ostream& os, const IdPair<IdType, DataType>& t) {
      56             :   return os << '(' << t.id << ',' << t.data << ')';
      57             : }
      58             : /// \endcond

Generated by: LCOV version 1.14