{"pageProps":{"code":{"CMakeLists.txt":{"name":"CMakeLists.txt","content":"add_executable(algos algos.cpp)\r\n\r\nadd_executable(bound bound.cpp)\r\n\r\nadd_executable(c-sum c-sum.cpp)\r\n\r\nadd_executable(find find.cpp)\r\n\r\nadd_executable(inserter inserter.cpp)\r\n\r\nadd_executable(lambda1 lambda1.cpp)\r\n\r\n# add_executable(ranges ranges.cpp)\r\n\r\nadd_executable(simple-sum1 simple-sum1.cpp)\r\n\r\nadd_executable(simple-sum2 simple-sum2.cpp)\r\n\r\nadd_executable(sum-stl sum-stl.cpp)\r\n\r\nadd_executable(transform transform.cpp)","path":"code/6771/25T2/2.3/CMakeLists.txt","fileext":"txt"},"algos.cpp":{"name":"algos.cpp","content":"#include <iostream>\r\n#include <numeric>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<int> v { 1, 2, 3, 4, 5 };\r\n    int sum = std::accumulate(v.begin(), v.end(), 0);\r\n\r\n    // What is the type of std::multiplies<int>()\r\n    int product = std::accumulate(v.begin(), v.end(), 1, std::multiplies<int>());\r\n    (void)product; // dummy line\r\n\r\n    auto midpoint = v.begin() + static_cast<int>(v.size() / 2);\r\n    // This looks a lot harder to read. Why might it be better?\r\n\r\n    auto midpoint11 = std::next(v.begin(), std::distance(v.begin(), v.end()) / 2);\r\n    (void)midpoint11;\r\n\r\n    int sum2 = std::accumulate(v.begin(), midpoint, 0);\r\n\r\n    std::cout << sum << \" \" << sum2 << \"\\n\";\r\n}\r\n","path":"code/6771/25T2/2.3/algos.cpp","fileext":"cpp"},"bound.cpp":{"name":"bound.cpp","content":"#include <algorithm>\r\n#include <iostream>\r\n#include <list>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    // Lower bound does a binary search, and returns the first value >= the argument.\r\n    std::vector<int> sortedVec { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\r\n    (void)std::lower_bound(sortedVec.begin(), sortedVec.end(), 5);\r\n\r\n    std::list<int> sortedLinkedList { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\r\n    (void)std::lower_bound(sortedLinkedList.begin(), sortedLinkedList.end(), 5);\r\n}\r\n","path":"code/6771/25T2/2.3/bound.cpp","fileext":"cpp"},"c-sum.cpp":{"name":"c-sum.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<int> nums { 1, 2, 3, 4, 5 };\r\n\r\n    auto sum = 0;\r\n    for (auto i = 0; i <= static_cast<int>(nums.size()); ++i) {\r\n        sum += i;\r\n    }\r\n\r\n    std::cout << sum << \"\\n\";\r\n}","path":"code/6771/25T2/2.3/c-sum.cpp","fileext":"cpp"},"find.cpp":{"name":"find.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<int> nums { 1, 2, 3, 4, 5 };\r\n\r\n    auto it = std::find(nums.begin(), nums.end(), 4);\r\n\r\n    if (it != nums.end()) {\r\n        std::cout << \"Found it!\"\r\n                  << \"\\n\";\r\n    }\r\n}\r\n","path":"code/6771/25T2/2.3/find.cpp","fileext":"cpp"},"inserter.cpp":{"name":"inserter.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nchar to_upper(char value)\r\n{\r\n    return static_cast<char>(std::toupper(static_cast<unsigned char>(value)));\r\n}\r\n\r\nint main()\r\n{\r\n\r\n    std::string s = \"hello world\";\r\n    // std::for_each modifies each element\r\n    std::for_each(s.begin(), s.end(), toupper);\r\n\r\n    std::string upper;\r\n    // std::transform adds to third iterator.\r\n    std::transform(s.begin(), s.end(), std::back_inserter(upper), to_upper);\r\n}\r\n","path":"code/6771/25T2/2.3/inserter.cpp","fileext":"cpp"},"lambda1.cpp":{"name":"lambda1.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::string s = \"hello world\";\r\n    // std::for_each modifies each element\r\n    std::for_each(s.begin(), s.end(), [](char& value) { value = static_cast<char>(std::toupper(value)); });\r\n}\r\n","path":"code/6771/25T2/2.3/lambda1.cpp","fileext":"cpp"},"ranges.cpp":{"name":"ranges.cpp","content":"/*#include <catch2/catch.hpp>\r\n#include <ranges>\r\n#include <vector>\r\n\r\nint main() {\r\n  auto const single_digits = std::vector<int>{\r\n    0, 1, 2, 3, 4, 5, 6, 7, 8, 9\r\n  };\r\n\r\n  more_single_digits.push_back(0);\r\n  CHECK(ranges::count(more_single_digits, 0) == 2);\r\n  more_single_digits.pop_back();\r\n  CHECK(ranges::count(more_single_digits, 0) == 1);\r\n  CHECK(std::erase(more_single_digits, 0) == 1);\r\n  CHECK(ranges::count(more_single_digits, 0) == 0);\r\n  CHECK(ranges::distance(more_single_digits) == 8);\r\n}*/","path":"code/6771/25T2/2.3/ranges.cpp","fileext":"cpp"},"simple-sum1.cpp":{"name":"simple-sum1.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<int> nums { 1, 2, 3, 4, 5 };\r\n\r\n    auto sum = 0;\r\n    for (auto it = nums.begin(); it != nums.end(); ++it) {\r\n        sum += *it;\r\n    }\r\n    std::cout << sum << \"\\n\";\r\n}","path":"code/6771/25T2/2.3/simple-sum1.cpp","fileext":"cpp"},"simple-sum2.cpp":{"name":"simple-sum2.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<int> nums { 1, 2, 3, 4, 5 };\r\n\r\n    int sum = 0;\r\n\r\n    // Internally, this uses begin and end,\r\n    // but it abstracts it away.\r\n    for (const auto& i : nums) {\r\n        sum += i;\r\n    }\r\n\r\n    std::cout << sum << \"\\n\";\r\n}","path":"code/6771/25T2/2.3/simple-sum2.cpp","fileext":"cpp"},"sum-stl-underlying.cpp":{"name":"sum-stl-underlying.cpp","content":"/*\r\ntemplate <typename T, typename Container>\r\nT sum(iterator_t<Container> first, iterator_t<Container> last) {\r\n  T total;\r\n  for (; first != last; ++first) {\r\n    total += *first;\r\n  }\r\n  return total\r\n}\r\n*/","path":"code/6771/25T2/2.3/sum-stl-underlying.cpp","fileext":"cpp"},"sum-stl.cpp":{"name":"sum-stl.cpp","content":"#include <iostream>\r\n#include <numeric>\r\n#include <vector>\r\n\r\nint main()\r\n{\r\n    std::vector<int> nums { 1, 2, 3, 4, 5 };\r\n    int sum = std::accumulate(nums.begin(), nums.end(), 0);\r\n    std::cout << sum << \"\\n\";\r\n}","path":"code/6771/25T2/2.3/sum-stl.cpp","fileext":"cpp"},"transform.cpp":{"name":"transform.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nchar to_upper(unsigned char value)\r\n{\r\n    return static_cast<char>(std::toupper(static_cast<unsigned char>(value)));\r\n}\r\n\r\nint main()\r\n{\r\n\r\n    std::string s = \"hello world\";\r\n    // Algorithms like transform, which have output iterators,\r\n    // use the other iterator as an output.\r\n    auto upper = std::string(s.size(), '\\0');\r\n    std::transform(s.begin(), s.end(), upper.begin(), to_upper);\r\n}\r\n","path":"code/6771/25T2/2.3/transform.cpp","fileext":"cpp"}}},"__N_SSG":true}