Skip to main content

Posts

Showing posts from February, 2018

Part2 : STL Algorithms (Non-Modifying sequence) in c++

3.  Non-Modifying sequence operations:   s earch std::vector vecStack;          int vecNeedle1[] = { 40,50,60,70 };          int vecNeedle2[] = { 20,30,50 }; std::vector ::iterator it_search; // vecStack: 10 20 30 40 50 60 70 80 90 for (int i = 1; i // using default comparison: 1. it_search = std::search ( vecStack.begin() , vecStack.end() , vecNeedle1 , vecNeedle1 + 4 ); if (it_search != vecStack.end()) std::cout << "search: needle1 found at position " << (it_search - vecStack.begin()) << '\n'; else std::cout << "search : needle1 not found\n"; // using predicate comparison: auto val = vecNeedle2 + 3; it_search = std::search ( vecStack.begin() , vecStack.end() , vecNeedle2 , vecNeedle2 + 3 , myfunction ); if (it_search != vecStack.end()) std::cout << "search: needle2 found at position " << (it_search - vecStack.begin()) ...

Part1 : STL Algorithms (Non-Modifying sequence) in c++

Non-Modifying sequence operations : 1.  Non-modifying sequence operations:   _of (CPP 11) std::array all_of_elem = { 3,5,7,11,13,17,19,23 }; 1. if ( std::all_of ( all_of_elem.begin(),   all_of_elem.end() ,  [](int i) {return i % 2; } )) std::cout << "All the elements are odd numbers.\n"; std::array any_of_elem = { 0,1,-1,3,-3,5,-5 }; 2. if ( std::any_of ( any_of_elem.begin() ,  any_of_elem.end() ,  [](int i) {return i )) std::cout << "There are negative elements in the range.\n"; std::array foo = { 1,2,4,8,16,32,64,128 }; 3. if ( std::none_of ( foo.begin() ,  foo.end() ,  [](int i) {return i )) std::cout << "There are no negative elements in the range.\n"; 2.  Non-modifying sequence operations:   find       std::string myints[] = { "Hello", "Hi", "Bye", "ByeBye" }; std::vector myvector(myints, myints + 4); std::vector ::iterator it;...