AutoPas  3.0.0
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
autopas::utils::ArrayUtils Namespace Reference

In this namespace some helper functions for std::array can be found. More...

Namespaces

namespace  is_container_impl
 Collection of structs that define what we consider a container.
 

Classes

struct  is_container
 

Functions

template<class output_t , class input_t , std::size_t SIZE>
constexpr std::array< output_t, SIZE > static_cast_copy_array (const std::array< input_t, SIZE > &a)
 Creates a new array by performing an element-wise static_cast<>.
 
template<class Container , class Fun >
void to_string (std::ostream &os, const Container &container, const std::string &delimiter, const std::array< std::string, 2 > &surround, Fun elemToString)
 Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend) and appends it to a stream.
 
template<class Container >
void to_string (std::ostream &os, const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
 Version of to_string() with simpler signature and default arguments.
 
template<class Container , class Fun >
std::string to_string (const Container &container, const std::string &delimiter, const std::array< std::string, 2 > &surround, Fun elemToString)
 Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend).
 
template<class Container >
std::string to_string (const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
 Version of to_string() with simpler signature and default arguments.
 
template<class Container >
std::enable_if_t< autopas::utils::ArrayUtils::is_container< Container >::value, std::ostream & > operator<< (std::ostream &os, const Container &container)
 Stream operator for containers (array and vector types).
 
template<class OuterContainerT >
void balanceVectors (OuterContainerT &vecvec)
 Given a collection of vectors, redistributes the elements of the vectors so they all have the same (or +1) size.
 
template<class OuterContainerT , class F >
void balanceVectors (OuterContainerT &vecvec, F innerContainerToVec)
 Given a collection of containers that hold vectors, redistributes the elements of the vectors so they all have the same (or +1) size.
 

Detailed Description

In this namespace some helper functions for std::array can be found.

Function Documentation

◆ balanceVectors() [1/2]

template<class OuterContainerT >
void autopas::utils::ArrayUtils::balanceVectors ( OuterContainerT &  vecvec)

Given a collection of vectors, redistributes the elements of the vectors so they all have the same (or +1) size.

Elements are taken from the ends of too-long vectors and appended to the ends of too-short vectors. The overall ordering of elements is not preserved.

Template Parameters
OuterContainerTCollection type
Parameters
vecvecReference to the collection of vectors to be balanced in place.

◆ balanceVectors() [2/2]

template<class OuterContainerT , class F >
void autopas::utils::ArrayUtils::balanceVectors ( OuterContainerT &  vecvec,
innerContainerToVec 
)

Given a collection of containers that hold vectors, redistributes the elements of the vectors so they all have the same (or +1) size.

Elements are taken from the ends of too-long vectors and appended to the ends of too-short vectors. The overall ordering of elements is not preserved.

Template Parameters
OuterContainerTCollection type
FType of the function innerContainerToVec
Parameters
vecvecReference to the collection of vectors to be balanced in place.
innerContainerToVecFunction to map inner containers to std::vector&.

◆ operator<<()

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

Stream operator for containers (array and vector types).

This function actually checks if the given Template parameter satisfies is_container. Then Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend)

Template Parameters
arrayor vector of arbitrary types and sizes
Parameters
osstring stream
container
Returns
string representation of a container

◆ static_cast_copy_array()

template<class output_t , class input_t , std::size_t SIZE>
constexpr std::array< output_t, SIZE > autopas::utils::ArrayUtils::static_cast_copy_array ( const std::array< input_t, SIZE > &  a)
constexpr

Creates a new array by performing an element-wise static_cast<>.

Note
This function returns a new copy of the array with the desired type!

Even though this is implemented to copy the array, compilers optimize this away: https://gcc.godbolt.org/z/6dav1PEGP

Template Parameters
output_tOutput type.
input_tInput type.
SIZESize of the array.
Parameters
aInput array.
Returns
Array of type std::array<output_t, SIZE>.

◆ to_string() [1/4]

template<class Container , class Fun >
std::string autopas::utils::ArrayUtils::to_string ( const Container &  container,
const std::string &  delimiter,
const std::array< std::string, 2 > &  surround,
Fun  elemToString 
)

Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend).

Note
std::boolalpha is always enabled.
Template Parameters
TType of Container.
FunFunction type (Container::element) -> implicit std::string
Parameters
container
elemToStringFunction converting one element of container to something that is implicitly convertible to std::string.
delimiterString that is put between items.
surroundStrings to be put before and after the listing (e.g. brackets).
Returns
String representation of container.

◆ to_string() [2/4]

template<class Container >
std::string autopas::utils::ArrayUtils::to_string ( const Container &  container,
const std::string &  delimiter = ", ",
const std::array< std::string, 2 > &  surround = {"[", "]"} 
)

Version of to_string() with simpler signature and default arguments.

Template Parameters
Container
Parameters
container
delimiter
surround
Returns

◆ to_string() [3/4]

template<class Container , class Fun >
void autopas::utils::ArrayUtils::to_string ( std::ostream &  os,
const Container &  container,
const std::string &  delimiter,
const std::array< std::string, 2 > &  surround,
Fun  elemToString 
)

Generates a string representation of a container which fulfills the Container requirement (provide cbegin and cend) and appends it to a stream.

Template Parameters
Container
FunFunction type (Container::element) -> implicit std::string
Parameters
os
container
elemToStringFunction converting one element of container to something that is implicitly convertible to std::string.
delimiter
surround

◆ to_string() [4/4]

template<class Container >
void autopas::utils::ArrayUtils::to_string ( std::ostream &  os,
const Container &  container,
const std::string &  delimiter = ", ",
const std::array< std::string, 2 > &  surround = {"[", "]"} 
)

Version of to_string() with simpler signature and default arguments.

Template Parameters
Container
Parameters
os
container
delimiter
surround