Rewrite the code from C++11 to C++03.

The question was asked: 7 years 0 months ago   views: 41
0

Hello, help to rewrite the code from the C++11 standard C++03 standard.

#include <iostream> #include <iterator> #include <string> #include <cerrno> #include <cstdlib> #include <iostream> #include <boost/foreach.hpp> using namespace std; class directory_range { directory_range(bfs_dir_iter itr): _itr(itr) bfs_dir_iter _itr; public: directory_range(bfs_dir_iter&& itr): _itr(itr) { } bfs_dir_iter begin() { return _itr; } bfs_dir_iter end() { return bfs_dir_iter(); } }; int main() { namespace bfs = boost::filesystem3; bfs::path p("/home/root/test/"); if(!bfs::is_directory(p)) { std::cerr << "[ ERROR ] "; std::cerr << p << " isn't directory. Stopping...." << std::endl; return ENOENT; } const char** dirs_begin = dirs; const char* dirs[] = {"part1", "part2", "part3", "part4", "part5"}; BOOST_FOREACH(const char* dir, dirs) try { bfs::create_directory(p / dir); } catch(const bfs::filesystem_error& e) { std::cerr << "[ ERROR ] "; std::cerr << (p / dir).filename() << " is already exists and not directory. " << "Stopping..." << std::endl; return ENOENT; } const char** dirs_iter = dirs; BOOST_FOREACH (const bfs::directory_entry& file, std::make_pair(bfs::directory_iterator(p), bfs::directory_iterator())) { if(!bfs::is_regular_file(file)) { std::cerr << "[WARNING] "; std::cerr << file.path().filename() << " isn't regular file. " << "Go to the hell, I will not copy it." << std::endl; } else { if(bfs::exists(p / *dirs_iter / file.path().filename())) { std::cerr << "[WARNING] "; std::cerr << file.path().filename() << "is already exists in" << *dirs_iter << ". Skipping..." << std::endl; continue; } bfs::copy(file, p / *dirs_iter++ / file.path().filename()); if(dirs_iter == dirs_end) dirs_iter = dirs_begin; } } return 0; }
Asked: 12-08-2012 в 23:19:17
And what's the problem? Remove all rvalue references, auto, and range-based for - and it works. - 13-08-2012 в 01:04:06
Here you will advise. Not just clean, but to rewrite in the standard With++2003 - 13-08-2012 в 01:14:57
Yes it need to be rewritten... - 13-08-2012 в 01:43:00
@karr, According to the rules of the forum, questions should not be limited to the proposals to complete the work. Write that are not clear. - 13-08-2012 в 01:44:25
And sorry, well not understand specifically what to remove, add, change the code to meet the C++standard 2003, I with these standards and do not bother-you will never... - 13-08-2012 в 01:56:59

Answers   1

0

Something like that. for (:) replaced BOOST_FOREACH and everywhere explicitly specify types instead of auto:

6a7 > #include <boost/foreach.hpp> 14c15 < directory_range(bfs_dir_iter&& itr): _itr(itr) --- > directory_range(bfs_dir_iter itr): _itr(itr) 41a43,44 > const char** dirs_begin = dirs; > const char** dirs_end = dirs + sizeof(dirs) / sizeof(const char*); 43c46 < for(const auto& dir: dirs) --- > BOOST_FOREACH(const char* dir, dirs) 57,58c60,63 < auto dirs_iter = std::begin(dirs); < for(const auto& file: directory_range(bfs::directory_iterator(p))) --- > const char** dirs_iter = dirs; > BOOST_FOREACH (const bfs::directory_entry& file, > std::make_pair(bfs::directory_iterator(p), > bfs::directory_iterator())) 78,79c83,84 < if(dirs_iter == std::end(dirs)) < dirs_iter = std::begin(dirs); --- > if(dirs_iter == dirs_end) > dirs_iter = dirs_begin;
Answered: 13-08-2012 в 11:07:06
Began to replace, turned out a complete mess of some sort...In the end, not Campillos, as I expected... - 13-08-2012 в 14:11:38
Telepaths on vacation. - 13-08-2012 в 14:20:49
@karr You've been given a patch, as we can remove / not add? - 13-08-2012 в 16:09:44
@karr, review to ensure that these changes had not to make with your hands, and apply with the patch utility. Shared fixed file pastie.org/4466091. - 13-08-2012 в 17:13:38
Then mark the answer to the question as stated (accepted) - 13-08-2012 в 18:17:41