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

DRY (Don't Repeat Yourself) utilities and macros. More...

#include <cstddef>
#include <tuple>
#include <functional>
#include <sstream>
#include <initializer_list>
#include <ahFunctional.H>
#include <ah-errors.H>
Include dependency graph for ahDry.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::Dft_Pair_Cmp< Key, Data, Cmp >
 Default comparator for pair types in hash maps. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 

Macros

#define Special_Ctors(Set_Type, Type)
 Generates special constructors for containers.
 
#define Generic_Items(Type)
 Generates an items() method returning all container elements.
 
#define Generate_Proxy_Operator(Class_Name)
 Generates operator[] for map-like containers.
 

Functions

template<typename Type >
std::string Aleph::to_str (const Type &d)
 Converts any streamable value to string.
 
template<typename Key , typename Data >
std::pair< Key, Data > * Aleph::key_to_pair (Key *ptr)
 Converts a pointer to Key to a pointer to the containing pair.
 
template<typename Key , typename Data >
const std::pair< Key, Data > * Aleph::key_to_pair (const Key *ptr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename Key , typename Data >
std::pair< Key, Data > * Aleph::data_to_pair (Data *ptr)
 Converts a pointer to Data to a pointer to the containing pair.
 
template<typename Key , typename Data >
const std::pair< Key, Data > * Aleph::data_to_pair (const Data *ptr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 

Detailed Description

DRY (Don't Repeat Yourself) utilities and macros.

This file provides utility macros that implement common patterns to avoid code repetition.

Active Macros

Deprecated Macros (REMOVED)

The following macros have been migrated to CRTP classes in ah-dry.H and ah-dry-mixin.H:

For new code, prefer using the CRTP classes from ah-dry.H or the documented mixins from ah-dry-mixin.H.

See also
ah-dry.H for CRTP class implementations
ah-dry-mixin.H for documented mixin implementations
Author
Leandro Rabindranath León

Definition in file ahDry.H.

Macro Definition Documentation

◆ Generate_Proxy_Operator

#define Generate_Proxy_Operator (   Class_Name)
Value:
const Data & operator [] (const Key & key) const \
{ \
return find(key); \
} \
\
Data & operator [] (const Key & key) \
{ \
return find(key); \
}

Generates operator[] for map-like containers.

Parameters
Class_NameThe container class name (unused, kept for compatibility)

Definition at line 151 of file ahDry.H.

◆ Generic_Items

#define Generic_Items (   Type)
Value:
template <template <typename> class Container = DynList> \
Container<Type> items() const \
{ \
return this->template maps<Type, Container> ([] (const Type & key) \
{ return key; }); \
}

Generates an items() method returning all container elements.

Parameters
TypeThe element type
Note
For new code, consider using KeysMixin from ah-dry-mixin.H instead.

Definition at line 139 of file ahDry.H.

◆ Special_Ctors

#define Special_Ctors (   Set_Type,
  Type 
)
Value:
template <template <typename> class List> \
Set_Type(const List<Type> & l) : Set_Type() \
{ \
l.for_each([this] (const Type & item) { (void)this->append(item); }); \
} \
\
template <class It> \
Set_Type(It b, It e) : Set_Type() \
{ \
for (It it = b; it != e; ++it) \
(void)this->append(*it); \
} \
\
Set_Type(std::initializer_list<Type> l) : Set_Type() \
{ \
for (const auto & item : l) \
(void)this->append(item); \
}
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:685
DynList< int > l

Generates special constructors for containers.

This macro generates three constructors:

  1. Constructor from any list-like container with for_each method
  2. Constructor from iterator pair [begin, end)
  3. Constructor from std::initializer_list
Note
This cannot be migrated to CRTP because constructors don't inherit in C++.
Parameters
Set_TypeThe container class name
TypeThe element type

Example:

template <typename T>
class MyContainer {
// ... members ...
public:
MyContainer() = default;
Special_Ctors(MyContainer, T);
};
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Definition ahDry.H:113

Definition at line 113 of file ahDry.H.