Hello, help rewrite code from c ++ 11 standard under 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; } 
  • one
    What's the problem? Remove all the rvalue references, auto and range-based for - and everything works. - dzhioev
  • one
    You are here to advise. Do not just remove, but rewrite within the framework of the standard C ++ 2003 - skegg
  • Yes, it is necessary to rewrite ... - karr
  • one
    @karr, According to the rules of the forum, questions should not be reduced to offers to do the work. Write what's not clear. - skegg
  • And sorry, well, it is not clear exactly what needs to be removed, added, changed, so that the code meets the C ++ 2003 standard, I never bother with these standards ... - karr

1 answer 1

Something like this. for (:) change to BOOST_FOREACH and explicitly indicate the types everywhere, 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; 
  • Began to replace, it turned out some kind of porridge ... In the end, it did not compile, as I expected ... - karr
  • one
    Telepaths on vacation. - dzhioev
  • 2
    @karr You were given a patch, how can you not remove / add something? - Costantino Rupert
  • 2
    @karr, a comment to the fact that these changes should not have been made by hand, but applied using the patch utility. Share the corrected file pastie.org/4466091 . - dzhioev
  • one
    Then mark the answer to the question as marked (accepted) - gecube