MolSim
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
ArrayUtils.h File Reference

Utility functions for working with iterable data containers. More...

#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

Go to the source code of this file.

Classes

struct  ArrayUtils::is_container_impl::is_container< T >
 Default case: T is not a container. More...
 
struct  ArrayUtils::is_container_impl::is_container< std::array< T, N > >
 Specialization to allow std::array. More...
 
struct  ArrayUtils::is_container_impl::is_container< std::vector< Args... > >
 Specialization to allow std::vector. More...
 
struct  ArrayUtils::is_container_impl::is_container< std::list< Args... > >
 Specialization to allow std::list. More...
 
struct  ArrayUtils::is_container_impl::is_container< std::set< Args... > >
 Specialization to allow std::set. More...
 
struct  ArrayUtils::is_container_impl::is_container< std::unordered_set< Args... > >
 Specialization to allow std::unordered_set. More...
 
struct  ArrayUtils::is_container< T >
 Type trait to check if a given type is a container. More...
 

Namespaces

namespace  ArrayUtils
 Collection of utility functions and operators for iterable data containers like std::array, std::vector, etc.
 
namespace  ArrayUtils::is_container_impl
 Collection of structs that define what we consider a container. Remove / add whatever you need.
 

Functions

template<class Container >
std::string ArrayUtils::to_string (const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
 Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend).
 
template<class Container , class F >
Container ArrayUtils::elementWisePairOp (const Container &lhs, const Container &rhs, F binaryFunction)
 Applies an element wise binary function F to two containers.
 
template<class Scalar , class Container , class F >
Container ArrayUtils::elementWiseScalarOp (const Scalar &lhs, const Container &rhs, F binaryFunction)
 Applies a binary function F to with a scalar to every element in a container.
 
template<class Container >
auto ArrayUtils::L2NormSquared (const Container &c)
 Calculates the square of the L2 norm for a given container.
 
template<class Container >
auto ArrayUtils::L2Norm (const Container &c)
 Calculates the L2 norm for a given container.
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, std::ostream & > operator<< (std::ostream &os, const Container &container)
 Stream operator for containers.
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator+ (const Container &lhs, const Container &rhs)
 Element wise addition of two containers.
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator- (const Container &lhs, const Container &rhs)
 Element wise subtraction of two containers.
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator* (const Container &lhs, const Container &rhs)
 Element wise multiplication of two containers.
 
template<class Scalar , class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator* (const Scalar &lhs, const Container &rhs)
 Element wise scaling of a container.
 
template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, bool > operator== (const Container &lhs, const Container &rhs)
 Element wise comparison of two containers.
 

Detailed Description

Utility functions for working with iterable data containers.

Author
F. Gratl
Date
2019-12-13

Function Documentation

◆ operator*() [1/2]

template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator* ( const Container &  lhs,
const Container &  rhs 
)

Element wise multiplication of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs[i] * rhs[i].

◆ operator*() [2/2]

template<class Scalar , class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator* ( const Scalar &  lhs,
const Container &  rhs 
)

Element wise scaling of a container.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs * rhs[i].

◆ operator+()

template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator+ ( const Container &  lhs,
const Container &  rhs 
)

Element wise addition of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs[i] + rhs[i].

◆ operator-()

template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, Container > operator- ( const Container &  lhs,
const Container &  rhs 
)

Element wise subtraction of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
For all i lhs[i] - rhs[i].

◆ operator<<()

template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, std::ostream & > operator<< ( std::ostream &  os,
const Container &  container 
)

Stream operator for containers.

This function actually checks if the given Template parameter satisfies is_container.

Template Parameters
Container
Parameters
os
container
Returns

◆ operator==()

template<class Container >
std::enable_if_t< ArrayUtils::is_container< Container >::value, bool > operator== ( const Container &  lhs,
const Container &  rhs 
)

Element wise comparison of two containers.

Template Parameters
Container
Parameters
lhs
rhs
Returns
True iff the containers are of the same size, all elements are equal, and in the same order.