/* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TNT_UTILS_COMPRESSED_PAIR_H #define TNT_UTILS_COMPRESSED_PAIR_H #include #include namespace utils { template struct dependent_type : public T { }; template, bool> = true> struct compressed_pair : private T1, private T2 { template, Dummy>::value && dependent_type, Dummy>::value>> compressed_pair() : T1(), T2() {} template compressed_pair(U1&& other1, U2&& other2) : T1(std::forward(other1)), T2(std::forward(other2)) {} T1& first() noexcept { return static_cast(*this); } T2& second() noexcept { return static_cast(*this); } T1 const& first() const noexcept { return static_cast(*this); } T2 const& second() const noexcept { return static_cast(*this); } void swap(compressed_pair& other) noexcept { using std::swap; swap(first(), other.first()); swap(second(), other.second()); } }; } // namespace utils #endif // TNT_UTILS_COMPRESSED_PAIR_H