Skip to content

datatypes::utils::STLHelper

Helper functions with features found in other languages but not found in the C++ standard template library. Many of these features are not used in this library (uchronia) as such, but are here as a place of convenience for dependent modelling libraries.

#include <common.h>

Public Functions

Name
template <typename K =string,typename V =string>
bool
HasKey(const map< K, V > & dict, const string & key)
is a key present in a dictionary (map)
template <typename K =string,typename V =string>
vector< K >
GetKeys(const map< K, V > & dict)
Gets the keys present in a dictionary (map)
template <typename K =string,typename V =string>
map< K, V >
Remap(const map< K, V > & dict, const map< K, K > & newKeys)
Change the keys of a dictionary with new keys, remaping.
template <typename K =string,typename V =string>
map< K, V >
Zip(const vector< K > & key, const vector< V > & values)
template <typename K =string,typename V =string>
vector< V >
GetValues(const map< K, V > & dict)
Gets the values of a dictionary (map)
template <typename K =string,typename V =string>
vector< V >
GetValues(const map< K, V > & dict, const vector< K > & keys)
Gets the values of a dictionary (map), for a set of keys.
template <typename U >
bool
LessThan(const U & first, const U & second)
template <typename U >
bool
MoreThan(const U & first, const U & second)
template <typename K ,typename V >
vector< V >
SortValues(const std::map< K, V > & in, const vector< K > & order)
Gets the values of a dictionary (map), in the order specified by a set of keys.
template <typename T >
vector< T >
Serialize(const vector< vector< T >> & series)
Flatten jagged vectors to a one dimension vector.
template <typename T ,typename U >
vector< T >
SortFromRef(const vector< T > & in, const vector< U > & reference, std::function< bool(const U &, const U &)> comparer =STLHelper::LessThan< U >)
Reorder the values in one vector, based on the sorting of a second vector, using a specified comparer. Acknowledgements: derived from http://stackoverflow.com/a/236199/2752565, Konrad Rudolph.

Public Functions Documentation

function HasKey

template <typename K  =string,
typename V  =string>
static inline bool HasKey(
    const map< K, V > & dict,
    const string & key
)

is a key present in a dictionary (map)

function GetKeys

template <typename K  =string,
typename V  =string>
static inline vector< K > GetKeys(
    const map< K, V > & dict
)

Gets the keys present in a dictionary (map)

function Remap

template <typename K  =string,
typename V  =string>
static inline map< K, V > Remap(
    const map< K, V > & dict,
    const map< K, K > & newKeys
)

Change the keys of a dictionary with new keys, remaping.

Parameters:

  • dict
  • newKeys

Template Parameters:

  • K key type
  • V value type

Return: map

function Zip

template <typename K  =string,
typename V  =string>
static inline map< K, V > Zip(
    const vector< K > & key,
    const vector< V > & values
)

function GetValues

template <typename K  =string,
typename V  =string>
static inline vector< V > GetValues(
    const map< K, V > & dict
)

Gets the values of a dictionary (map)

function GetValues

template <typename K  =string,
typename V  =string>
static inline vector< V > GetValues(
    const map< K, V > & dict,
    const vector< K > & keys
)

Gets the values of a dictionary (map), for a set of keys.

function LessThan

template <typename U >
static inline bool LessThan(
    const U & first,
    const U & second
)

function MoreThan

template <typename U >
static inline bool MoreThan(
    const U & first,
    const U & second
)

function SortValues

template <typename K ,
typename V >
static inline vector< V > SortValues(
    const std::map< K, V > & in,
    const vector< K > & order
)

Gets the values of a dictionary (map), in the order specified by a set of keys.

function Serialize

template <typename T >
static inline vector< T > Serialize(
    const vector< vector< T >> & series
)

Flatten jagged vectors to a one dimension vector.

function SortFromRef

template <typename T ,
typename U >
static inline vector< T > SortFromRef(
    const vector< T > & in,
    const vector< U > & reference,
    std::function< bool(const U &, const U &)> comparer =STLHelper::LessThan< U >
)

Reorder the values in one vector, based on the sorting of a second vector, using a specified comparer. Acknowledgements: derived from http://stackoverflow.com/a/236199/2752565, Konrad Rudolph.


Updated on 2022-08-21 at 18:10:33 +1000