Skip to content

733. Flood Fill#9

Open
ryosuketc wants to merge 1 commit intomainfrom
733_flood_fill
Open

733. Flood Fill#9
ryosuketc wants to merge 1 commit intomainfrom
733_flood_fill

Conversation

@ryosuketc
Copy link
Owner

int num_cols = image[0].size();

// 1. 再帰呼び出し用のラムダ式を std::function として宣言
std::function<void(int, int)> dfs;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

念の為 C++ lambda と function class は異なるものです。

私は C++ の場合は外で関数にしたいですね。テストも書きやすいですし。このあたりに色々あります。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.yfb442pj2a6p

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function class (https://cpprefjp.github.io/reference/functional/function.html) の方は、ラムダ式を含む、より包括的な概念だという理解です。
積極的に使うことは少ないかもしれませんが、C++ ラムダについてはまだ全く使える気がしないので、機会があれば適宜練習してみたいと思います。

int original_color = image[sr][sc];
int num_rows = image.size();
int num_cols = image[0].size();
std::set<std::pair<int, int>> visited;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

二次元座標を表すにあたり、 std::pair を避け、独自の構造体を作る方もいらっしゃると思います。所属するチームの平均的なソフトウェアエンジニアの書き方に合わせることをおすすめします。

なお、二次元座標を表すにあたり、 std::complex を使うという方法もなくはないのですが、分かりづらく、利点は少ないように感じます。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。#11 でちょうどそのような感じの問題があったので class で書いてみました (C++ style guide の struct vs. class のあたりも参照しました)。

std::complex を知らなかったので調べてみたところ、虚数を表すためのものなんですね。
https://cpprefjp.github.io/reference/complex/complex.html
座標系を表すのはクラスの趣旨から外れるのではないかと思いましたが、こういった議論もあるんですね。
https://qiita.com/SaitoAtsushi/items/28e0ca10dd06f3a8c99b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants