Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
Loading...
Searching...
No Matches
iterator_example.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
22#include "core/container.h"
23#include <algorithm>
24#include <iostream>
25#include <numeric>
26
27using namespace kcenon::container;
28
30{
31 std::cout << "\n=== Range-Based For Loop ===" << std::endl;
32
33 value_container container;
34
35 // Note: For demonstration, we're showing the concept
36 // In actual use, you would populate the container with data
37 std::cout << "Container size: " << container.size() << std::endl;
38 std::cout << "Container empty: " << (container.empty() ? "yes" : "no") << std::endl;
39
40 // Example of range-based for loop (when container has data)
41 std::cout << "Range-based for loop syntax:" << std::endl;
42 std::cout << " for (const auto& value : container) {" << std::endl;
43 std::cout << " // Process each optimized_value" << std::endl;
44 std::cout << " }" << std::endl;
45}
46
48{
49 std::cout << "\n=== STL Algorithms ===" << std::endl;
50
51 value_container container;
52
53 // Example 1: find_if
54 std::cout << "find_if example:" << std::endl;
55 std::cout << " auto it = std::find_if(container.begin(), container.end()," << std::endl;
56 std::cout << " [](const optimized_value& val) {" << std::endl;
57 std::cout << " return val.type == value_types::int_value;" << std::endl;
58 std::cout << " });" << std::endl;
59
60 // Example 2: count_if
61 std::cout << "\ncount_if example:" << std::endl;
62 std::cout << " size_t count = std::count_if(container.begin(), container.end()," << std::endl;
63 std::cout << " [](const optimized_value& val) {" << std::endl;
64 std::cout << " return val.type == value_types::string_value;" << std::endl;
65 std::cout << " });" << std::endl;
66
67 // Example 3: for_each
68 std::cout << "\nfor_each example:" << std::endl;
69 std::cout << " std::for_each(container.begin(), container.end()," << std::endl;
70 std::cout << " [](const optimized_value& val) {" << std::endl;
71 std::cout << " std::cout << val.name << std::endl;" << std::endl;
72 std::cout << " });" << std::endl;
73}
74
76{
77 std::cout << "\n=== Iterator Properties ===" << std::endl;
78
79 value_container container;
80
81 std::cout << "Iterator methods available:" << std::endl;
82 std::cout << " container.begin() - returns iterator to first element" << std::endl;
83 std::cout << " container.end() - returns iterator to past-the-end" << std::endl;
84 std::cout << " container.cbegin() - returns const_iterator to first element" << std::endl;
85 std::cout << " container.cend() - returns const_iterator to past-the-end" << std::endl;
86 std::cout << " container.size() - returns number of elements" << std::endl;
87 std::cout << " container.empty() - returns true if empty" << std::endl;
88
89 std::cout << "\nIterator types:" << std::endl;
90 std::cout << " using iterator = std::vector<optimized_value>::iterator;" << std::endl;
91 std::cout << " using const_iterator = std::vector<optimized_value>::const_iterator;" << std::endl;
92}
93
94int main()
95{
96 std::cout << "========================================" << std::endl;
97 std::cout << "Container Iterator Support Examples" << std::endl;
98 std::cout << "========================================" << std::endl;
99
103
104 std::cout << "\n========================================" << std::endl;
105 std::cout << "Examples completed successfully!" << std::endl;
106 std::cout << "========================================" << std::endl;
107
108 return 0;
109}
void demonstrate_iterator_properties()
int main()
void demonstrate_stl_algorithms()
void demonstrate_range_based_for()