I'm facing with an issue. Returning std::pair<T1, T2> from lambda function. I'm trying to generate map with opened ifstream's, but compiler complains with this output:
/usr/include/c++/9/bits/stl_algo.h:4337:12: error: use of deleted function βstd::pair<const std::__cxx11::basic_string, std::basic_ifstream >& std::pair<const std::__cxx11::basic_string, std::basic_ifstream >::operator=(const std::pair<const std::__cxx11::basic_string, std::basic_ifstream >&)β
I went through cppref for std::pair and I didn't notice that copy operator= is not viable for this one.
I'm fairly certain that lambdas that return pair is possible, then I definitely have some misunderstanding in snippet below.
std::map<int, std::string> mFileMap;
std::map<std::string, std::ifstream> files;
std::transform(mFileMap.begin(), mFileMap.end(), files.begin(),
[](const auto& arg) -> std::pair<std::string, std::ifstream> {
std::string path(arg.second);
std::ifstream stream(path);
return std::make_pair(path, stream);
});