Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

and_thenにおける謎の暗黙変換 #5

Open
onihusube opened this issue Feb 12, 2021 · 1 comment
Open

and_thenにおける謎の暗黙変換 #5

onihusube opened this issue Feb 12, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@onihusube
Copy link
Owner

std::error_code f();

bool g();

int main() {
  // 1. 通る
  harmony::invert(f())
    | and_then([](auto&&) { return g() ? std::optional<bool>{true} : std::nullopt; });

  // 2. 通らない
  harmony::invert(f())
    | and_then([](auto&&) { return harmony::to_either(g(), false); });
}

and_thenでは有効値は渡された関数で変換するが、無効値は推定した戻り値型のコンストラクタにその時点の無効値を渡すことで変換する。つまり、上記1ではint -> std::optional<bool>への変換が暗黙に行われており、結果は明らかに意図したものと異なる(無効値は意図せず有効値として次の処理に渡される)。

このことはおそらくor_elseでも起こる。もしかしたら他のところでも・・・

@onihusube
Copy link
Owner Author

うーんどうしよう・・・

@onihusube onihusube added the bug Something isn't working label Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant