mdds
ref_pair.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 // SPDX-FileCopyrightText: 2020 - 2025 Kohei Yoshida
4 //
5 // SPDX-License-Identifier: MIT
6 
7 #pragma once
8 
9 #include <type_traits>
10 
11 namespace mdds { namespace detail {
12 
13 template<typename T1, typename T2>
14 struct ref_pair
15 {
16  using first_type = typename std::add_lvalue_reference<T1>::type;
17  using second_type = typename std::add_lvalue_reference<T2>::type;
18 
19  first_type first;
20  second_type second;
21 
22  ref_pair(first_type _first, second_type _second) : first(_first), second(_second)
23  {}
24 
25  ref_pair(const ref_pair& other) = default;
26 
27  bool operator==(const std::pair<typename std::decay<T1>::type, typename std::decay<T2>::type>& other) const
28  {
29  return first == other.first && second == other.second;
30  }
31 
32  bool operator!=(const std::pair<typename std::decay<T1>::type, typename std::decay<T2>::type>& other) const
33  {
34  return !operator==(other);
35  }
36 
37  bool operator==(const ref_pair& other) const
38  {
39  return first == other.first && second == other.second;
40  }
41 
42  bool operator!=(const ref_pair& other) const
43  {
44  return !operator==(other);
45  }
46 
47  ref_pair* operator->()
48  {
49  return this;
50  }
51 };
52 
53 }} // namespace mdds::detail
54 
55 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: ref_pair.hpp:14
Definition: cref_wrapper.hpp:12