int main(int argc, char* argv[]) { std::uniform_int_distribution<int> distribution(0, 99); std::mt19937 engine; auto generator = std::bind(distribution, engine); std::vector<int> numbers; std::generate_n(std::back_inserter(numbers), 50, generator); auto even_number_iterators = make_conditional_begin_and_end(numbers.begin(), numbers.end(), [](int x) { return x % 2 == 0; }); int count = 0; auto even_number_with_count_iterators = make_transform_iterator_begin_and_end( even_number_iterators.first, even_number_iterators.second, [&](int x) -> std::string { std::stringstream ss; ss << x << ":" << count++; return ss.str(); }); std::ostream_iterator<std::string> osi(std::cout, " "); std::copy(even_number_with_count_iterators.first, even_number_with_count_iterators.second, osi); std::cout << std::endl; }
int main(int argc, char* argv[]) { std::random_device rd; std::uniform_int_distribution<int> distribution(-10, 10); std::mt19937 engine(rd()); auto generator = std::bind(distribution, engine); int count = 10; std::vector<int> myInts; // = {-7, -7, 8, 9, -1, -7, -5, 1, -7, 5}; myInts.reserve(count); std::generate_n(std::back_inserter(myInts), count, generator); std::ostream_iterator<int> osi(std::cout, " "); std::copy(begin(myInts), end(myInts), osi); std::cout << " [Values]" << std::endl; std::vector<int>::const_iterator it_max_begin; std::vector<int>::const_iterator it_max_end; std::tie(it_max_begin, it_max_end) = max_subarray(myInts.cbegin(), myInts.cend()); std::copy(it_max_begin, it_max_end, osi); std::cout << " [Values with largest consecutive sum [" << std::distance(myInts.cbegin(), it_max_begin) << ':' << std::distance(myInts.cbegin(), it_max_end) << ") ]" << std::endl; }
static uint64_t approach1(const uint64_t num) { auto factors = primeFactors(num); std::ostream_iterator<uint64_t> osi(std::cout, " "); copy(factors.begin(), factors.end(), osi); std::cout << '\n'; return factors.back(); }
int main() { str test("test"); getline(std::cin,test); std::ostream_iterator<char> osi(std::cout); osi << test; return 0; }
int main(void) { int arr[6] = { 1, 2, 3, 4, 5, 6 }; std::vector<int> obV(arr, arr+6); std::ostream_iterator<int, char> osi(std::cout, " "); std::copy(obV.begin(), obV.end(), osi); std::cout<<std::endl; return 0; }
int main(int argc, char* argv[]) { std::vector<int> numbers = {1, 2, 3, 5, 6, 7, 5, 4, 3, 2, 3, 4, 5, 7, 9, 2, 1, 3, 4, 5, 7, 3}; auto isThree = [](int x) { return x == 3; }; auto conditional_begin_end = make_conditional_begin_and_end(numbers.begin(), numbers.end(), isThree); std::ostream_iterator<int> osi(std::cout, " "); std::copy(numbers.begin(), numbers.end(), osi); std::cout << "\n3 appears in the list " << std::count_if(numbers.begin(), numbers.end(), isThree) << " times" << std::endl; std::copy(conditional_begin_end.first, conditional_begin_end.second, osi); std::cout << std::endl; }
void iscrtaj(void) { double a = 8.0; // duljina stranice kocke double d = 0.5; // odmak od osi glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3d(1.0, 1.0, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(32.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); glRotated(kut, 0.0, 0.0, 1.0); glRotated(kut, 0.0, 1.0, 0.0); glRotated(kut, 1.0, 0.0, 0.0); osi(20.0); glTranslated(d, d, d); cone(2.5, 5.0, 20); glutSwapBuffers(); } // iscrtaj
void bcp_implementation::copy_path(const fs::path& p) { assert(!fs::is_directory(m_boost_path / p)); if(fs::exists(m_dest_path / p)) { std::cout << "Copying (and overwriting) file: " << p.string() << "\n"; fs::remove(m_dest_path / p); } else std::cout << "Copying file: " << p.string() << "\n"; // // create the path to the new file if it doesn't already exist: // create_path(p.branch_path()); // // do text based copy if requested: // if(p.leaf() == "Jamroot") { static std::vector<char> v1, v2; v1.clear(); v2.clear(); std::ifstream is((m_boost_path / p).c_str()); std::copy(std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>(), std::back_inserter(v1)); static boost::regex libname_matcher; if(libname_matcher.empty()) { libname_matcher.assign("boost_"); } regex_replace(std::back_inserter(v2), v1.begin(), v1.end(), libname_matcher, m_namespace_name + "_"); std::swap(v1, v2); v2.clear(); std::ofstream os; if(m_unix_lines) os.open((m_dest_path / p).c_str(), std::ios_base::binary | std::ios_base::out); else os.open((m_dest_path / p).c_str(), std::ios_base::out); os.write(&*v1.begin(), v1.size()); os.close(); } else if(m_namespace_name.size() && m_lib_names.size() && is_jam_file(p)) { static std::vector<char> v1, v2; v1.clear(); v2.clear(); std::ifstream is((m_boost_path / p).c_str()); std::copy(std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>(), std::back_inserter(v1)); static boost::regex libname_matcher; if(libname_matcher.empty()) { std::string re = "\\<"; re += *m_lib_names.begin(); for(std::set<std::string>::const_iterator i = ++m_lib_names.begin(); i != m_lib_names.end(); ++i) { re += "|" + *i; } re += "\\>"; libname_matcher.assign(re); } regex_replace(std::back_inserter(v2), v1.begin(), v1.end(), libname_matcher, get_new_library_name(m_namespace_name)); std::swap(v1, v2); v2.clear(); std::ofstream os; if(m_unix_lines) os.open((m_dest_path / p).c_str(), std::ios_base::binary | std::ios_base::out); else os.open((m_dest_path / p).c_str(), std::ios_base::out); os.write(&*v1.begin(), v1.size()); os.close(); } else if(m_namespace_name.size() && is_source_file(p)) { // // v1 hold the current content, v2 is temp buffer. // Each time we do a search and replace the new content // ends up in v2: we then swap v1 and v2, and clear v2. // static std::vector<char> v1, v2; v1.clear(); v2.clear(); std::ifstream is((m_boost_path / p).c_str()); std::copy(std::istreambuf_iterator<char>(is), std::istreambuf_iterator<char>(), std::back_inserter(v1)); static const boost::regex namespace_matcher( "(?|" "(namespace\\s+)boost(_\\w+)?(?:(\\s*::\\s*)phoenix)?" "|" "(namespace\\s+)(adstl|phoenix|rapidxml)\\>" "|" "()\\<boost((?:_(?!intrusive_tags)\\w+)?\\s*(?:::))(?:(\\s*)phoenix)?" "|" "()\\<((?:adstl|phoenix|rapidxml)\\s*(?:::))" "|" "(namespace\\s+\\w+\\s*=\\s*(?:::\\s*)?)boost(_\\w+)?(?:(\\s*::\\s*)phoenix)?" "|" "(namespace\\s+\\w+\\s*=\\s*(?:::\\s*)?(?:\\w+\\s*::\\s*)?)(adstl|phoenix|rapidxml)\\>" "|" "(^\\s*#\\s*define\\s+\\w+\\s+)boost((?:_\\w+)?\\s*)$" "|" "(^\\s*#\\s*define[^\\n]+)((?:adstl|phoenix|rapidxml)\\s*)$" "|" "()boost(_asio_detail_posix_thread_function|_regex_free_static_mutex)" "|" "()(lw_thread_routine|at_thread_exit|on_process_enter|on_process_exit|on_thread_enter|on_thread_exit|tss_cleanup_implemented)" "|" "(BOOST_CLASS_REQUIRE4?[^;]*)boost((?:_\\w+)?\\s*,)" "|" "(\\(\\s*)boost(\\s*\\))" ")" ); regex_replace(std::back_inserter(v2), v1.begin(), v1.end(), namespace_matcher, "$1" + m_namespace_name + "$2(?3$3" + m_namespace_name + "phoenix)", boost::regex_constants::format_all); std::swap(v1, v2); v2.clear(); if(m_namespace_alias) { static const boost::regex namespace_alias( /* "namespace\\s+" + m_namespace_name + "\\s*" "(" "\\{" "(?:" "(?>[^\\{\\}/]+)" "(?>" "(?:" "(?1)" "|//[^\\n]+$" "|/[^/]" "|(?:^\\s*#[^\\n]*" "(?:(?<=\\\\)\\n[^\\n]*)*)" ")" "[^\\{\\}]+" ")*" ")*" "\\}" ")" */ /* "(namespace\\s+" + m_namespace_name + "\\s*\\{.*" "\\})([^\\{\\};]*)\\z" */ "namespace\\s+" + m_namespace_name + "\\s*\\{" ); regex_replace(std::back_inserter(v2), v1.begin(), v1.end(), namespace_alias, "namespace " + m_namespace_name + "{} namespace boost = " + m_namespace_name + "; namespace " + m_namespace_name + "{"); std::swap(v1, v2); v2.clear(); } std::ofstream os; if(m_unix_lines) os.open((m_dest_path / p).c_str(), std::ios_base::binary | std::ios_base::out); else os.open((m_dest_path / p).c_str(), std::ios_base::out); if(v1.size()) os.write(&*v1.begin(), v1.size()); os.close(); } else if(m_unix_lines && !is_binary_file(p)) { std::ifstream is((m_boost_path / p).c_str()); std::istreambuf_iterator<char> isi(is); std::istreambuf_iterator<char> end; std::ofstream os((m_dest_path / p).c_str(), std::ios_base::binary | std::ios_base::out); std::ostreambuf_iterator<char> osi(os); std::copy(isi, end, osi); } else { // binary copy: fs::copy_file(m_boost_path / p, m_dest_path / p); } }