File indexing completed on 2024-04-28 16:53:07
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Ivan Čukić <ivan.cukic(at)kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef ASYNQT_EITHER_H 0008 #define ASYNQT_EITHER_H 0009 0010 #include "expected.h" 0011 0012 namespace AsynQt 0013 { 0014 template<typename T1, typename T2> 0015 class Either : private Expected<T1, T2> 0016 { 0017 public: 0018 template<typename... ConsParams> 0019 static Either left(ConsParams &&...params) 0020 { 0021 return Expected<T1, T2>::success(std::forward<ConsParams>(params)...); 0022 } 0023 0024 template<typename... ConsParams> 0025 static Either right(ConsParams &&...params) 0026 { 0027 return Expected<T1, T2>::error(std::forward<ConsParams>(params)...); 0028 } 0029 0030 Either(T1 value) 0031 { 0032 auto tmp = Either::left(value); 0033 this->swap(tmp); 0034 } 0035 0036 Either(T2 value) 0037 { 0038 auto tmp = Either::right(value); 0039 this->swap(tmp); 0040 } 0041 0042 T1 &left() 0043 { 0044 return Expected<T1, T2>::get(); 0045 } 0046 0047 T1 left() const 0048 { 0049 return Expected<T1, T2>::get(); 0050 } 0051 0052 T2 &right() 0053 { 0054 return Expected<T1, T2>::error(); 0055 } 0056 0057 T2 right() const 0058 { 0059 return Expected<T1, T2>::error(); 0060 } 0061 0062 Either(const Either &other) = default; 0063 Either(Either &&other) = default; 0064 0065 Either &operator=(const Either &other) = default; 0066 Either &operator=(Either &&other) = default; 0067 }; 0068 0069 } // namespace AsynQt 0070 0071 #endif // ASYNQT_EITHER_H