SpECTRE Documentation Coverage Report
Current view: top level - DataStructures - IdPair.hpp Hit Total Coverage
Commit: 923cd4a8ea30f5a5589baa60b0a93e358ca9f8e8 Lines: 1 7 14.3 %
Date: 2025-11-07 19:37:56
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 :   IdPair();
      18           0 :   IdPair(IdType id_in, DataType data_in);
      19             : 
      20           0 :   IdType id{};
      21           0 :   DataType data{};
      22             : };
      23             : 
      24             : template <typename IdType, typename DataType>
      25             : IdPair<IdType, DataType>::IdPair() = default;
      26             : 
      27             : template <typename IdType, typename DataType>
      28             : IdPair<IdType, DataType>::IdPair(IdType id_in, DataType data_in)
      29             :     : id(std::move(id_in)), data(std::move(data_in)) {}
      30             : 
      31             : template <typename IdType, typename DataType>
      32           0 : IdPair<std::decay_t<IdType>, std::decay_t<DataType>> make_id_pair(
      33             :     IdType&& id, DataType&& data) {
      34             :   return {std::forward<IdType>(id), std::forward<DataType>(data)};
      35             : }
      36             : 
      37             : /// \cond
      38             : // We write the pup function as a free function to keep IdPair a POD
      39             : // clang-tidy: no non-const references
      40             : template <typename IdType, typename DataType>
      41             : void pup(PUP::er& p, IdPair<IdType, DataType>& t) {  // NOLINT
      42             :   p | t.id;
      43             :   p | t.data;
      44             : }
      45             : 
      46             : // clang-tidy: no non-const references
      47             : template <typename IdType, typename DataType>
      48             : void operator|(PUP::er& p, IdPair<IdType, DataType>& t) {  // NOLINT
      49             :   pup(p, t);
      50             : }
      51             : 
      52             : template <typename IdType, typename DataType>
      53             : bool operator==(const IdPair<IdType, DataType>& lhs,
      54             :                 const IdPair<IdType, DataType>& rhs) {
      55             :   return lhs.id == rhs.id and lhs.data == rhs.data;
      56             : }
      57             : 
      58             : template <typename IdType, typename DataType>
      59             : bool operator!=(const IdPair<IdType, DataType>& lhs,
      60             :                 const IdPair<IdType, DataType>& rhs) {
      61             :   return not(lhs == rhs);
      62             : }
      63             : 
      64             : template <typename IdType, typename DataType>
      65             : std::ostream& operator<<(std::ostream& os, const IdPair<IdType, DataType>& t) {
      66             :   return os << '(' << t.id << ',' << t.data << ')';
      67             : }
      68             : /// \endcond

Generated by: LCOV version 1.14