167using namespace Aleph;
176 cout <<
"+" << string(70,
'-') <<
"+" << endl;
177 cout <<
"| " << left << setw(68) << title <<
" |" << endl;
178 cout <<
"+" << string(70,
'-') <<
"+" << endl;
183 cout <<
"\n " << subtitle << endl;
184 cout <<
" " << string(subtitle.length(),
'-') << endl;
187template <
typename Container>
190 cout <<
" " << name <<
" (" << c.size() <<
" elements): ";
191 for (
const auto& item : c)
199 cout <<
" " << name <<
" (" <<
l.
size() <<
" elements): ";
200 for (
auto it =
l.
get_it(); it.has_curr(); it.next_ne())
201 cout << it.get_curr() <<
" ";
208 cout <<
" " << name <<
" (" << arr.
size() <<
" elements): ";
209 for (
size_t i = 0; i < arr.
size(); ++i)
210 cout << arr(i) <<
" ";
220 print_header(
"Example 1: std::vector <-> DynList Conversions");
223 vector<string> cities_vec = {
224 "Bogota",
"Medellin",
"Cali",
"Barranquilla",
"Cartagena"
236 cout <<
" (vector_to_DynList also works)" << endl;
241 cities_list.
append(
"Santa Marta");
242 cities_list.
append(
"Bucaramanga");
245 vector<string> cities_vec2 =
to_vector(cities_list);
251 vector<int> population = {8281, 2569, 2228, 1274, 1047};
258 int total = pop_list.
foldl(0, [](
int acc,
int p) {
return acc + p; });
259 cout <<
" Total population: " << total <<
" thousand" << endl;
268 print_header(
"Example 2: std::vector <-> DynArray Conversions");
271 vector<double> areas = {63612, 23188, 22140, 44640, 25020, 24885};
282 areas_arr.
append(30000.5);
283 areas_arr.
append(55000.0);
289 double total =
accumulate(areas_vec2.begin(), areas_vec2.end(), 0.0);
290 double avg = total / areas_vec2.size();
292 cout <<
"\n Statistics (using STL algorithms):" << endl;
293 cout <<
" Total area: " << fixed << setprecision(1) << total <<
" km2" << endl;
294 cout <<
" Average: " << avg <<
" km2" << endl;
303 print_header(
"Example 3: std::list <-> DynList Conversions");
306 list<string> rivers_stl = {
307 "Magdalena",
"Cauca",
"Atrato",
"Meta",
"Guaviare",
"Caqueta"
319 rivers_aleph.
append(
"Putumayo");
320 rivers_aleph.
append(
"Orinoco");
328 set<int> altitude_set = {2640, 1538, 995, 18, 5, 213, 965};
331 cout <<
" (Note: set maintains sorted order)" << endl;
343 vector<double> temps = {23.5, 25.1, 24.8, 26.2, 22.9, 27.0, 25.5, 24.0};
363 int days[] = {1, 2, 3, 4, 5, 6, 7};
379 auto production = make_tuple(125000, 98000, 85000, 72000, 65000);
381 cout <<
" Tuple elements: ";
392 auto regions = make_tuple(
string(
"Huila"),
string(
"Narino"),
393 string(
"Cauca"),
string(
"Tolima"));
395 cout <<
" Tuple elements: ";
402 cout <<
" Regions Array (" << regions_arr.
size() <<
" elements): ";
403 for (
auto it = regions_arr.
get_it(); it.has_curr(); it.next_ne())
404 cout << it.get_curr() <<
" ";
409 auto mixed = make_tuple(42, 3.14159,
string(
"Colombia"),
'C');
411 cout <<
" Processing heterogeneous tuple:" << endl;
413 cout <<
" -> " << val << endl;
428 vector<int> scores = variadic_to_vector<int>(95, 87, 92, 78, 88, 91);
432 vector<double> rates = variadic_to_vector<double>(4.5, 3.8, 4.2, 4.0);
438 "Cafe",
"Flores",
"Banano",
"Carbon",
"Petroleo"
445 auto cities = variadic_to_DynList<string>(
446 "Leticia",
"Mitú",
"Puerto Inírida",
"San José del Guaviare"
449 cout <<
" Amazon region cities:" << endl;
450 for (
auto it = cities.get_it(); it.has_curr(); it.next_ne())
451 cout <<
" - " << it.get_curr() << endl;
465 vector<double> gdp = {6500, 8200, 7800, 5900, 12000};
469 auto gdp_cop =
map_vector(gdp, [](
double usd) {
return usd * 4150.0; });
471 cout <<
" GDP per capita (COP): ";
472 for (
const auto& v : gdp_cop)
473 cout << fixed << setprecision(0) << v <<
" ";
479 auto gdp_strings =
map_vector(gdp, [](
double val) {
480 return "$" +
to_string(
static_cast<int>(val)) +
" USD";
486 vector<int> quantities = {10, 25, 15, 30, 20};
490 auto with_discount =
map_vector(quantities, [](
int q) {
504 print_header(
"Example 8: Integration - Processing Pipeline");
506 cout <<
"\n Scenario: Process sales data from STL to Aleph-w and back\n" << endl;
509 vector<pair<string, double>> sales = {
511 {
"Medellin", 890000},
513 {
"Barranquilla", 450000},
514 {
"Cartagena", 380000}
517 cout <<
" Step 1: Original STL data (city, sales)" << endl;
518 for (
const auto& [city, amount] : sales)
519 cout <<
" " << left << setw(15) << city << fixed << setprecision(0)
520 << amount <<
" COP" << endl;
523 vector<string> cities;
524 vector<double> amounts;
525 for (
const auto& [city, amount] : sales) {
526 cities.push_back(city);
527 amounts.push_back(amount);
534 cout <<
"\n Step 2: Converted to Aleph-w DynList" << endl;
535 cout <<
" Cities: " << cities_list.
size() <<
" items" << endl;
536 cout <<
" Amounts: " << amounts_list.
size() <<
" items" << endl;
539 double total = amounts_list.
foldl(0.0, [](
double acc,
double v) {
543 double avg = total / amounts_list.
size();
545 auto above_avg = amounts_list.
filter([avg](
double v) {
549 cout <<
"\n Step 3: Aleph-w processing" << endl;
550 cout <<
" Total sales: " << fixed << setprecision(0) << total <<
" COP" << endl;
551 cout <<
" Average: " << avg <<
" COP" << endl;
552 cout <<
" Cities above average: " << above_avg.
size() << endl;
555 vector<double> above_vec =
to_vector(above_avg);
557 cout <<
"\n Step 4: Back to STL for output" << endl;
558 cout <<
" Sales above average: ";
559 for (
double v : above_vec)
571 cout <<
"========================================================================" << endl;
572 cout <<
" ALEPH-W STL UTILS EXAMPLE" << endl;
573 cout <<
" STL <-> Aleph-w Container Conversions" << endl;
574 cout <<
"========================================================================" << endl;
586 cout <<
"========================================================================" << endl;
587 cout <<
" Example completed successfully!" << endl;
588 cout <<
"========================================================================" << endl;
Conversion utilities between Aleph-w containers and STL containers.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
size_t size() const noexcept
Return the current dimension of array.
T & append()
Allocate a new entry to the end of array.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
size_t size() const noexcept
Return the number of items of the list, in constant time.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
Acc foldl(const Acc &init, Op &op) const
Fold the elements of the container to a specific result.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
Array< T > tuple_to_array(const std::tuple< T, U... > &t)
Convert a tuple to an Array.
auto range_to_DynList(Iterator begin, Iterator end) -> DynList< std::decay_t< decltype(*begin)> >
Convert an iterator range to a DynList.
DynList< T > to_DynList(const Array< T > &a)
Convert an Array to a DynList.
DynList< T > list_to_DynList(const std::list< T > &l)
Convert a std::list to a DynList.
T accumulate(Itor beg, Itor end, T initValue)
Accumulate values in a range.
DynList< T > vector_to_DynList(const std::vector< T > &v)
Convert a std::vector to a DynList.
DynList< T > tuple_to_dynlist(const std::tuple< T, U... > &t)
Convert a tuple to a DynList.
auto stl_container_to_dynList(const StlContainer &container) -> DynList< typename StlContainer::value_type >
Convert any STL container to a DynList.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
DynArray< T > vector_to_DynArray(const std::vector< T > &v)
Convert a std::vector to a DynArray.
std::vector< T > DynArray_to_vector(const DynArray< T > &arr)
Convert a DynArray to a std::vector.
std::list< T > DynList_to_list(const DynList< T > &l)
Convert a DynList to a std::list.
void tuple_for_each(const std::tuple< Ts... > &tuple, F func, std::index_sequence< Is... >)
Apply a function to each element in a tuple (tuple first).
std::vector< typename C::Item_Type > to_vector(const C &c)
Convert a container to a std::vector.
auto map_vector(const std::vector< T > &v, Op op) -> std::vector< std::decay_t< decltype(op(v[0]))> >
Map a function over a std::vector.
void demo_vector_dynlist()
void demo_range_conversions()
void print_dynlist(const string &name, const DynList< T > &l)
void demo_variadic_packing()
void print_dynarray(const string &name, const DynArray< T > &arr)
void demo_tuple_conversions()
void demo_map_transformations()
void print_subheader(const string &subtitle)
void demo_vector_dynarray()
void print_stl_container(const string &name, const Container &c)
Lazy and scalable dynamic array implementation.