- 981 名前:デフォルトの名無しさん mailto:sage [2022/04/13(水) 12:12:18.93 ID:5KnL277L.net]
- // A と Bのところだけが異なるfとf2
// うまくこの関数をまとめれませんか? #include <iostream> #include <vector> #include <algorithm> struct Foo { void Func() const {} }; void f(const std::vector<Foo>& vf) { std::for_each(vf.begin(),vf.end(), [](auto&& f) { f.Func();//A } ); } void f2(const std::vector<Foo*>& vf) { std::for_each(vf.begin(),vf.end(), [](auto&& f) { f->Func();//B } ); } int main( int argc, char *argv[] ) { std::vector<Foo> vf; std::vector<Foo*> vfp; f(vf); f2(vfp); }
|

|