Skip to content

Commit 2632bf4

Browse files
committed
adds support for clang
1 parent 32c356d commit 2632bf4

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

neither/include/either.hpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct Either {
139139
class R2 = R>
140140
constexpr auto join() const
141141
-> decltype(
142-
isCopyable(leftValue, rightValue),
142+
isCopyable((L2)leftValue, (R2)rightValue),
143143
std::declval<std::common_type_t<L2, R2>>()
144144
) {
145145
return isLeft? leftValue : rightValue;
@@ -160,41 +160,42 @@ struct Either {
160160
return isLeft? leftCase( leftValue ) : rightCase( rightValue );
161161
}
162162

163-
template<class F>
164-
constexpr auto leftMap(F const& leftCase) const& -> Either<decltype(leftCase( isCopyable(leftValue, rightValue) )), R> {
165-
using NextEither = Either<decltype(leftCase(leftValue)), R>;
163+
template<class F, class L2=L, class R2=R>
164+
constexpr auto leftMap(F const& leftCase) const&
165+
-> Either<decltype(leftCase( isCopyable((L2)leftValue, (R2)rightValue) )), R2> {
166+
using NextEither = Either<decltype(leftCase(leftValue)), R2>;
166167
return isLeft ?
167168
NextEither::leftOf( leftCase( leftValue ) ) :
168169
NextEither::rightOf( rightValue );
169170
}
170171

171-
template<class F>
172-
auto leftMap(F const& leftCase)&& -> Either<decltype(leftCase(std::move(leftValue))), R> {
173-
using NextEither = Either<decltype(leftCase(std::move(leftValue))), R>;
172+
template<class F, class L2=L, class R2=R>
173+
auto leftMap(F const& leftCase)&& -> Either<decltype(leftCase(std::move(leftValue))), R2> {
174+
using NextEither = Either<decltype(leftCase(std::move(leftValue))), R2>;
174175
return isLeft ?
175176
NextEither::leftOf(leftCase(std::move(leftValue))) :
176177
NextEither::rightOf( std::move(rightValue) );
177178
}
178179

179-
template<class F>
180-
constexpr auto rightMap(F const& rightCase) const& -> Either<L, decltype(rightCase(isCopyable(rightValue, leftValue)))> {
180+
template<class F, class L2=L, class R2=R>
181+
constexpr auto rightMap(F const& rightCase) const& -> Either<L, decltype(rightCase(isCopyable((R2)rightValue, (L2)leftValue)))> {
181182
using NextEither = Either<L, decltype(rightCase(rightValue))>;
182183
return isLeft ?
183184
NextEither::leftOf( leftValue ) :
184185
NextEither::rightOf( rightCase( rightValue ) );
185186
}
186187

187-
template<class F>
188-
auto rightMap(F const& rightCase)&& -> Either<L, decltype(rightCase(std::move(rightValue)))> {
188+
template<class F, class L2=L, class R2=R>
189+
auto rightMap(F const& rightCase)&& -> Either<L2, decltype(rightCase(std::move((R2)rightValue)))> {
189190
using NextEither = Either<L, decltype(rightCase(std::move(rightValue)))>;
190191
return isLeft ?
191192
NextEither::leftOf( std::move(leftValue) ) :
192193
NextEither::rightOf( rightCase( std::move(rightValue) ) );
193194
}
194195

195-
template<class LeftCase>
196+
template<class LeftCase, class L2=L, class R2=R>
196197
constexpr auto leftFlatMap(LeftCase const& leftCase) const&
197-
-> decltype( ensureEitherRight(leftCase(isCopyable(leftValue)), isCopyable(rightValue))) {
198+
-> decltype( ensureEitherRight(leftCase(isCopyable((L2)leftValue)), isCopyable((R2)rightValue))) {
198199
using NextEither = decltype(leftCase(leftValue));
199200

200201
if (!*this) {
@@ -204,9 +205,9 @@ struct Either {
204205
return NextEither::rightOf(rightValue);
205206
}
206207

207-
template<class RightCase>
208+
template<class RightCase, class L2=L, class R2=R>
208209
constexpr auto rightFlatMap(RightCase const& rightCase) const&
209-
-> decltype( ensureEitherLeft(rightCase(isCopyable(rightValue)), isCopyable(leftValue))) {
210+
-> decltype( ensureEitherLeft(rightCase(isCopyable((R2)rightValue)), isCopyable((L2)leftValue))) {
210211
using NextEither = decltype(rightCase(rightValue));
211212

212213
if (*this) {
@@ -218,7 +219,7 @@ struct Either {
218219

219220

220221

221-
template<class LeftCase>
222+
template<class LeftCase, class L2=L, class R2=R>
222223
auto leftFlatMap(LeftCase const& leftCase)&&
223224
-> decltype( ensureEitherRight(leftCase(std::move(leftValue)), std::move(rightValue))) {
224225
using NextEither = decltype(leftCase(std::move(leftValue)));
@@ -230,7 +231,7 @@ struct Either {
230231
return NextEither::rightOf(std::move(rightValue));
231232
}
232233

233-
template<class RightCase>
234+
template<class RightCase, class L2=L, class R2=R>
234235
auto rightFlatMap(RightCase const& rightCase)&&
235236
-> decltype( ensureEitherLeft(rightCase(std::move(rightValue)), std::move(leftValue))) {
236237
using NextEither = decltype(rightCase(std::move(rightValue)));

0 commit comments

Comments
 (0)