Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
stl_utils_example.C File Reference

Example demonstrating STL <-> Aleph-w container conversions. More...

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <ah-stl-utils.H>
#include <htlist.H>
#include <tpl_dynArray.H>
Include dependency graph for stl_utils_example.C:

Go to the source code of this file.

Functions

void print_header (const string &title)
 
void print_subheader (const string &subtitle)
 
template<typename Container >
void print_stl_container (const string &name, const Container &c)
 
template<typename T >
void print_dynlist (const string &name, const DynList< T > &l)
 
template<typename T >
void print_dynarray (const string &name, const DynArray< T > &arr)
 
void demo_vector_dynlist ()
 
void demo_vector_dynarray ()
 
void demo_list_dynlist ()
 
void demo_range_conversions ()
 
void demo_tuple_conversions ()
 
void demo_variadic_packing ()
 
void demo_map_transformations ()
 
void demo_integration ()
 
int main ()
 

Detailed Description

Example demonstrating STL <-> Aleph-w container conversions.

This example demonstrates seamless interoperability between Standard Template Library (STL) containers and Aleph-w containers using ah-stl-utils.H. This is essential for integrating Aleph-w with existing STL-based codebases and third-party libraries.

Why Container Interoperability?

Many C++ projects use STL containers (std::vector, std::list, etc.), while Aleph-w provides its own container types (DynList, DynArray, etc.). This utility bridge allows you to:

  • Use both: Leverage strengths of both container families
  • Integrate easily: Convert between formats as needed
  • Migrate gradually: Move from STL to Aleph-w incrementally
  • Interoperate: Work with libraries expecting STL containers

Features Demonstrated

Container Conversions

STL → Aleph-w

  • std::vector<T>DynList<T> / DynArray<T>
  • std::list<T>DynList<T>
  • std::set<T>DynSetTree<T>
  • Iterator ranges → Aleph containers

Aleph-w → STL

  • DynList<T>std::vector<T> / std::list<T>
  • DynArray<T>std::vector<T>
  • Any Aleph container → STL container

Advanced Conversions

Tuple Conversions

  • Convert tuples to containers
  • Useful for function return values
  • Unpack structured data

Iterator Ranges

  • Convert STL iterator ranges to Aleph containers
  • Convert Aleph iterator ranges to STL containers
  • Work with partial ranges

Variadic Arguments

  • Pack variadic arguments into containers
  • Useful for function templates
  • Flexible argument handling

Map Transformations

  • Convert between std::map and Aleph map types
  • Transform key-value structures
  • Preserve or transform data during conversion

Use Cases

Library Integration

  • Third-party APIs: Many libraries expect STL containers
  • Legacy code: Existing codebases using STL
  • Standard compliance: Some interfaces require STL types

Data Processing Pipelines

  • Input: Read data into STL containers
  • Process: Use Aleph-w algorithms (may be faster/better)
  • Output: Convert back to STL for compatibility

Migration Strategy

  • Phase 1: Use STL containers
  • Phase 2: Convert to Aleph-w where beneficial
  • Phase 3: Use conversion utilities for compatibility

Performance Optimization

  • Use Aleph-w containers for performance-critical sections
  • Convert to STL only when necessary for compatibility
  • Minimize conversion overhead

Conversion Overhead

Most conversions are O(n) where n is container size:

  • Copy conversion: Creates new container (memory overhead)
  • Move conversion: More efficient (if supported)
  • View conversion: Zero-copy (if available)

Best practice: Minimize conversions, convert once at boundaries.

Example Workflow

// Read data into STL vector (from external API)
std::vector<int> stl_data = read_from_api();
// Convert to Aleph-w for processing
DynList<int> aleph_data = vector_to_DynList(stl_data);
// Use Aleph-w algorithms (may be faster)
auto result = aleph_data.maps([](int x) { return x * 2; });
// Convert back to STL for output
std::vector<int> output = DynList_to_vector(result);
DynList< T > vector_to_DynList(const std::vector< T > &v)
Convert a std::vector to a DynList.
Definition ah-convert.H:250
ofstream output
Definition writeHeap.C:213

Usage

# Run all conversion examples
./stl_utils_example

This example has no command-line options; it runs all demos.

See also
ah-stl-utils.H STL/Aleph-w conversion utilities
uni_functional_example.C Unified functional operations (works with both)
zip_utils_example.C Unified zip operations (works with both)
Author
Leandro Rabindranath León

Definition in file stl_utils_example.C.

Function Documentation

◆ demo_integration()

◆ demo_list_dynlist()

◆ demo_map_transformations()

void demo_map_transformations ( )

◆ demo_range_conversions()

◆ demo_tuple_conversions()

◆ demo_variadic_packing()

void demo_variadic_packing ( )

◆ demo_vector_dynarray()

◆ demo_vector_dynlist()

◆ main()

◆ print_dynarray()

template<typename T >
void print_dynarray ( const string &  name,
const DynArray< T > &  arr 
)

Definition at line 206 of file stl_utils_example.C.

References Aleph::maps(), and Aleph::DynArray< T >::size().

Referenced by demo_vector_dynarray().

◆ print_dynlist()

template<typename T >
void print_dynlist ( const string &  name,
const DynList< T > &  l 
)

◆ print_header()

void print_header ( const string &  title)

Definition at line 173 of file stl_utils_example.C.

References Aleph::maps().

◆ print_stl_container()

template<typename Container >
void print_stl_container ( const string &  name,
const Container c 
)

◆ print_subheader()