LIBINT 2.7.2
compressed_pair.h
1/*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_lib_libint_util_compressedpair_h_
22#define _libint2_src_lib_libint_util_compressedpair_h_
23
24namespace libint2 {
25 namespace detail {
26
27 // a bare-bones implementation that assumes T1 and T2 are classes, and T1 != T2
28 template <class T1, class T2>
29 class compressed_pair : private T1, private T2
30 {
31 public:
32 typedef T1 first_type;
33 typedef T2 second_type;
34 typedef typename std::add_const<first_type>::type first_const_type;
35 typedef typename std::add_const<second_type>::type second_const_type;
36 typedef typename std::add_lvalue_reference<first_type>::type first_reference;
37 typedef typename std::add_lvalue_reference<second_type>::type second_reference;
38 typedef typename std::add_lvalue_reference<first_const_type>::type first_const_reference;
39 typedef typename std::add_lvalue_reference<second_const_type>::type second_const_reference;
40 typedef typename std::add_rvalue_reference<first_type>::type first_rvalue_reference;
41 typedef typename std::add_rvalue_reference<second_type>::type second_rvalue_reference;
42
43 compressed_pair() = default;
44 compressed_pair(const first_type& x, const second_type& y) :
45 first_type(x), second_type(y) {}
46 explicit compressed_pair(const first_type& x) : first_type(x) {}
47 explicit compressed_pair(const second_type& y) : second_type(y) {}
48
49 compressed_pair(const compressed_pair& other) = default;
51 first_type(std::move(other.first_rvalref())), second_type(std::move(other.second_rvalref())) {}
52 compressed_pair& operator=(const compressed_pair&) = default;
53 compressed_pair& operator=(compressed_pair&& other) {
54 this->first() = std::move(other.first_rvalref());
55 this->second() = std::move(other.second_rvalref());
56 return *this;
57 }
58
59 first_reference first() { return static_cast<first_reference>(*this); }
60 first_const_reference first() const { return static_cast<first_const_reference>(*this); }
61 first_rvalue_reference first_rvalref() { return static_cast<first_rvalue_reference>(*this); }
62
63 second_reference second() { return static_cast<second_reference>(*this); }
64 second_const_reference second() const { return static_cast<second_const_reference>(*this); }
65 second_rvalue_reference second_rvalref() { return static_cast<second_rvalue_reference>(*this); }
66
67 void swap(compressed_pair& other) {
68 swap(this->first(),other.first());
69 swap(this->second(),other.second());
70 }
71 };
72
73 template <class T1, class T2>
74 compressed_pair<T1,T2> make_compressed_pair(const T1& x, const T2& y) {
75 return compressed_pair<T1,T2>(x,y);
76 }
77
78 } // namespace libint2::detail
79} // namespace libint2
80#endif // header guard
81
82
Definition: compressed_pair.h:30
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24