Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
Utopia::Utils Namespace Reference

Classes

struct  apply
 Apply the metafunction 'Metafunc' to a tuplelike type 'Tuplelike'. More...
 
struct  get_size
 Return the size of a Type T containing other types at compile time. If no object for which an overload exists is passed, the get_size::value defaults to 1, indicating a scalar. If you want to have another type to be usable with get_size, provide an overload for it as shown by the various overloads existing for get_size already. More...
 
struct  get_size< arma::fmat::fixed< N, M > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::frowvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::fvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::imat::fixed< N, M > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::irowvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::ivec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::mat::fixed< N, M > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::rowvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::s32_mat::fixed< N, M > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::s32_rowvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::s32_vec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::u32_mat::fixed< N, M > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::u32_rowvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::u32_vec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::umat::fixed< N, M > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::urowvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::uvec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< arma::vec::fixed< N > >
 overload of get_size for armadillo type More...
 
struct  get_size< boost::hana::tuple< Ts... > >
 Overload for hana tuples. More...
 
struct  get_size< std::array< T, N > >
 Overload for std::array. More...
 
struct  get_size< std::pair< A, B > >
 Overload for std::pair. More...
 
struct  get_size< std::tuple< Ts... > >
 Overload for std::tuple. More...
 
struct  has_edge_descriptor
 Check if a type T has a edge descriptor. More...
 
struct  has_edge_descriptor< T, std::void_t< typename T::edge_descriptor > >
 Check if a type T has an edge descriptor. More...
 
struct  has_static_size
 Determine if type T is tuple_like, i.e., has a compile time constant size which is smaller than std::numeric_limits< std::size_t >::max() = 18446744073709551615. This size is unreasonable and hence used to check invalidity. More...
 
struct  has_static_size_base
 Determine if type T is 'tuplelike'. This is not intended to be used explicitly, refer to 'has_static_size', which serves this purpose. More...
 
struct  has_vertex_descriptor
 Check if a type T has a vertex descriptor. More...
 
struct  has_vertex_descriptor< T, std::void_t< typename T::vertex_descriptor > >
 Check if a type T has a vertex descriptor. More...
 
struct  is_array_like
 Check if a given type is homogeneous and has a size which is a compile time constant. The most common type which fulfils these requirements is std::array, hence the name 'is_array_like'. For a new type to be considered array_like, this functor has to be overloaded together with get_size. More...
 
struct  is_associative_container
 Check if a type T is an associative container type, i.e. a container type T that defines T::key_type and T::key_compare. Check out https://en.cppreference.com/w/cpp/named_req/AssociativeContainer for more details. More...
 
struct  is_associative_container< T, std::void_t< std::enable_if_t< is_container_v< T >, int >, typename T::key_type, typename T::key_compare > >
 Check if a type T is an associative container type, i.e. a container type T that defines T::key_type and T::key_compare. Check out https://en.cppreference.com/w/cpp/named_req/AssociativeContainer for more details. More...
 
class  is_callable
 Check if a type T is callable, i.e., if it has. More...
 
class  is_callable< T, std::void_t< std::enable_if_t< std::is_class_v< std::decay_t< T > >, T > > >
 Determines if the type T implements a call operator with arbitrary signature. More...
 
struct  is_container
 Check if a type is a container type, which does not include string types. More...
 
struct  is_container< T, std::void_t< std::enable_if_t< is_iterable_v< remove_qualifier_t< T > > and not is_string_v< remove_qualifier_t< T > >, int > > >
 Check if a type T is a container type. A container for us is every iterable that is not a string. More...
 
struct  is_graph
 Check if some type T is a graph by checking if it has edge - and vertex_descriptors. More...
 
struct  is_graph< T, std::void_t< std::enable_if_t< has_edge_descriptor_v< T > and has_vertex_descriptor_v< T >, int > > >
 Check if some type T is a graph by checking if it has edge_- and vertex_descriptors. More...
 
struct  is_iterable
 Check if a type T is iterable, i.e., if it defines T::iterable. More...
 
struct  is_iterable< T, std::void_t< typename T::iterator > >
 Check if a type T is iterable, i.e., if it defines T::iterable. More...
 
struct  is_linear_container
 Check if a type T is a linear container. A linear container for us is any type T that is a container and neither an associative nor an unordered associative container. More...
 
struct  is_linear_container< T, std::void_t< std::enable_if_t< not is_associative_container_v< T > and not is_unordered_associative_container_v< T > and is_container_v< T >, int > > >
 Check if a type T is a linear container. A linear container for us is any type T that is a container and neither an associative nor an unordered associative container. More...
 
struct  is_random_access_container
 Check if a type T is a random access container, i.e., any container type T that has an iterator tagged with std::random_access_iterator_tag. More...
 
struct  is_random_access_container< T, std::void_t< std::enable_if_t< is_linear_container_v< T > and std::is_convertible_v< typename std::iterator_traits< typename T::iterator >::iterator_category, std::random_access_iterator_tag > > > >
 Check if a type T is a random access container, i.e., any container type T that has an iterator tagged with std::random_access_iterator_tag. More...
 
struct  is_string
 Check if a type T is a string-like type, i.e. std::basic_string, const char*, char*, or basic_string_view. More...
 
struct  is_string< char * >
 Overload of is_string for pure char*. More...
 
struct  is_string< const char * >
 Overload of is_string for pure const char*. More...
 
struct  is_string< std::basic_string< Ts... > >
 Overload of is_string for basic_string. More...
 
struct  is_string< std::basic_string_view< Ts... > >
 Overload of is_string for basic_string_view. More...
 
struct  is_unordered_associative_container
 Check if a type T is an unordered associative container type, i.e. a container type T that defines T::key_type, T::value_type and T::hasher. Check out https://en.cppreference.com/w/cpp/named_req/UnorderedAssociativeContainer for more details. More...
 
struct  is_unordered_associative_container< T, std::void_t< std::enable_if_t< is_container_v< T >, int >, typename T::key_type, typename T::value_type, typename T::hasher > >
 Check if a type T is an unordered associative container type, i.e. a container type T that defines T::key_type, T::value_type and T::hasher. Check out https://en.cppreference.com/w/cpp/named_req/UnorderedAssociativeContainer for more details. More...
 
struct  Nothing
 Represent a type that does nothing and represents nothing, hence can be used in metaprogramming whenever no action is desired. More...
 
struct  remove_pointer
 Helper function for removing pointer qualifiers from a type recursivly This is the recursion base case. More...
 
struct  remove_pointer< T, std::enable_if_t< std::is_array_v< T >, std::void_t<> > >
 Oveload of remove_pointer metafunction for array types (stack allocated) More...
 
struct  remove_pointer< T, std::enable_if_t< std::is_pointer_v< T >, std::void_t<> > >
 Helper function for removing pointer qualifiers from a type recursivly Provides a member type definition called 'type' which is equal to T if the first template argument is of type T* or T** or T***... More...
 
struct  remove_qualifier
 Function for removing the qualifiers from a type T. Qualifiers are 'const', 'volative', pointer, reference or any legal combination thereof. More...
 

Typedefs

template<template< typename... > class Metafunc, typename Tuplelike >
using apply_t = typename apply< Metafunc, Tuplelike >::type
 Alias for apply for applying a metafunction to a tuple.
 
template<typename T >
using remove_pointer_t = typename remove_pointer< T >::type
 Shorthand for 'typename remove_pointer<T>::type'.
 
template<typename T >
using remove_qualifier_t = typename remove_qualifier< T >::type
 Shorthand for 'typename remove_qualifier::value'.
 

Functions

template<typename T , typename U >
std::ostream & operator<< (std::ostream &out, const std::pair< T, U > &pair)
 pretty print a pair
 
template<class T >
std::enable_if_t< is_container_v< T >, std::ostream & > operator<< (std::ostream &out, const T &container)
 
std::ostream & operator<< (std::ostream &out, const std::vector< bool > &container)
 Output container to stream 'out'- specialization for vector of booleans. Note that a vector of booleans is not the same as a vector of any other type because it does some storage optimization to make booleans take up single bits only.
 
template<template< typename, typename, typename... > class MapType, typename Key , typename Value , typename... Args>
std::enable_if_t< is_associative_container_v< MapType< Key, Value, Args... > > or is_unordered_associative_container_v< MapType< Key, Value, Args... > >, std::ostream & > operator<< (std::ostream &out, const MapType< Key, Value, Args... > &map)
 Output (unordered) associative containers to an std::ostream.
 
template<typename... Types>
std::ostream & operator<< (std::ostream &ostr, std::tuple< Types... > tuple)
 Report a tuple to an outstream, This works by piping the single elements inside the tuple to the stream, and therefor requires operator<< for the underlying types to be defined.
 
template<typename T >
std::string str (T &&t)
 Turn any object for which operator<< exists into a string. Mostly useful for logging data via spdlog which for instance cannot log containers per default.
 

Variables

template<typename T >
constexpr bool is_string_v = is_string< T >::value
 Shorthand for 'is_string<T>::value'.
 
template<typename T >
constexpr bool is_iterable_v = is_iterable< T >::value
 shorthand for is_iterable<T>::value
 
template<typename T >
constexpr bool is_container_v = is_container< T >::value
 Shorthand for 'is_container::value.
 
template<typename T >
constexpr bool is_associative_container_v
 Shorthand for is_associative_container<T>::value.
 
template<typename T >
constexpr bool is_unordered_associative_container_v
 Shorthand for is_unordered_associative_container<T>::value.
 
template<typename T >
constexpr bool is_linear_container_v = is_linear_container< T >::value
 Shorthand for is_linear_container<T>::value.
 
template<typename T >
constexpr bool is_random_access_container_v
 shorthand for is_linear_container<T>::value
 
template<typename T >
constexpr bool has_vertex_descriptor_v
 Shorthand for has_vertex_descriptor<T>::value.
 
template<typename T >
constexpr bool has_edge_descriptor_v = has_edge_descriptor< T >::value
 shothand for has_edge_descriptor<T>::value
 
template<typename T >
constexpr bool is_graph_v = is_graph< T >::value
 Shorthand for is_graph<T>::value.
 
template<typename T >
constexpr std::size_t get_size_v = get_size< T >::value
 
template<typename T >
constexpr bool is_array_like_v = is_array_like< T >::value
 Shorthand for is_array_like<T>::value.
 
template<typename T >
constexpr bool has_static_size_v = has_static_size< T >::value
 Shorthand for has_static_size::value.
 
template<typename T >
constexpr bool is_callable_v = is_callable< T >::value
 Shorthand for is_callable<T>::value.
 

Typedef Documentation

◆ apply_t

Alias for apply for applying a metafunction to a tuple.

Template Parameters
MetafuncA metafunction accepting as many template args as 'Tuplelike' is big.
TuplelikeA tuplelike object which can be exploded into a parameter pack with std::tuple_element

◆ remove_pointer_t

Shorthand for 'typename remove_pointer<T>::type'.

Template Parameters
Ttype to remove pointer for

◆ remove_qualifier_t

Shorthand for 'typename remove_qualifier::value'.

Function Documentation

◆ operator<<() [1/5]

template<typename... Types>
std::ostream & Utopia::Utils::operator<< ( std::ostream &  ostr,
std::tuple< Types... >  tuple 
)

Report a tuple to an outstream, This works by piping the single elements inside the tuple to the stream, and therefor requires operator<< for the underlying types to be defined.

For tuple values a, b, ..., the output will look like

(a, b, ...) 
136{
137 std::string val_str("(");
138
139 auto report_val = [&val_str](auto&& val) {
140 val_str += std::to_string(val) + ", ";
141 };
142 boost::hana::for_each(tuple, report_val);
143
144 // remove final comma
145 val_str.erase(val_str.end() - 2);
146 val_str += ")";
147
148 ostr << val_str;
149 return ostr;
150}

◆ operator<<() [2/5]

template<template< typename, typename, typename... > class MapType, typename Key , typename Value , typename... Args>
std::enable_if_t< is_associative_container_v< MapType< Key, Value, Args... > > or is_unordered_associative_container_v< MapType< Key, Value, Args... > >, std::ostream & > Utopia::Utils::operator<< ( std::ostream &  out,
const MapType< Key, Value, Args... > &  map 
)

Output (unordered) associative containers to an std::ostream.

Template Parameters
MapTypeSome type representing an (uordered) associative container, automatically determined.
KeyKey type of the container, automatically determined.
ValueMapped type of the container, automatically determined.
ArgsAdditional template args, automatically determined.
Parameters
outoutstream to use for output
mapMap like type, has to define key_type, map_type and have pair<const Key, Value> as value_type
Returns
std::ostream Used outstream
107{
108 if (map.size() == 0)
109 {
110 out << "[]";
111 }
112 else
113 {
114 out << "[";
115 for (auto it = map.begin();
116 it != std::next(map.begin(), map.size() - 1);
117 ++it)
118 {
119 out << *it << ", ";
120 }
121 out << *std::next(map.begin(), map.size() - 1) << "]";
122 }
123 return out;
124}

◆ operator<<() [3/5]

template<typename T , typename U >
std::ostream & Utopia::Utils::operator<< ( std::ostream &  out,
const std::pair< T, U > &  pair 
)

pretty print a pair

Template Parameters
Tfirst type in pair, automatically determined
Usecond type in pair, automatically determined
Parameters
outstream used for output
pairpair to put out
19{
20 out << "(" << pair.first << ", " << pair.second << ")";
21 return out;
22}

◆ operator<<() [4/5]

std::ostream & Utopia::Utils::operator<< ( std::ostream &  out,
const std::vector< bool > &  container 
)

Output container to stream 'out'- specialization for vector of booleans. Note that a vector of booleans is not the same as a vector of any other type because it does some storage optimization to make booleans take up single bits only.

Parameters
outstream used for output
containervector of booleans
Returns
std::ostream&
68{
69 if (container.size() == 0)
70 {
71 out << "[]" << std::endl;
72 }
73 else
74 {
75 out << "[";
76 for (std::size_t i = 0; i < container.size() - 1; ++i)
77 {
78 out << container[i] << ", ";
79 }
80 out << container.back() << "]";
81 }
82 return out;
83}

◆ operator<<() [5/5]

template<class T >
std::enable_if_t< is_container_v< T >, std::ostream & > Utopia::Utils::operator<< ( std::ostream &  out,
const T &  container 
)

Output the content of a container to the stream 'out' in the format '[x1, x2, x3, ...]' where the x_{i} are the elements the container holds. This does not(!) take care of outputting the elements, in the sense that an output operator for the latter has to be preexisting.

Parameters
outstream used for output
containerContainer object to output.
35{
36 if (container.size() == 0)
37 {
38 out << "[]";
39 }
40 else
41 {
42 out << std::setprecision(16) << "[";
43
44 for (auto it = container.begin();
45 it != std::next(std::begin(container), container.size() - 1);
46 ++it)
47 {
48 out << *it << ", "; // becomes a recursive call in case of nested
49 // containers
50 }
51 out << *std::next(std::begin(container), container.size() - 1) << "]";
52 }
53 return out;
54}

◆ str()

template<typename T >
std::string Utopia::Utils::str ( T &&  t)

Turn any object for which operator<< exists into a string. Mostly useful for logging data via spdlog which for instance cannot log containers per default.

Template Parameters
Tautomatically determined
Parameters
tobject to be turned into a string to be logged
Returns
std::string string representation provided by std::stringstream
165{
166 std::stringstream s;
167 s << t;
168 return s.str();
169}

Variable Documentation

◆ get_size_v

template<typename T >
constexpr std::size_t Utopia::Utils::get_size_v = get_size< T >::value
inlineconstexpr

◆ has_edge_descriptor_v

template<typename T >
constexpr bool Utopia::Utils::has_edge_descriptor_v = has_edge_descriptor< T >::value
inlineconstexpr

shothand for has_edge_descriptor<T>::value

◆ has_static_size_v

template<typename T >
constexpr bool Utopia::Utils::has_static_size_v = has_static_size< T >::value
inlineconstexpr

Shorthand for has_static_size::value.

◆ has_vertex_descriptor_v

template<typename T >
constexpr bool Utopia::Utils::has_vertex_descriptor_v
inlineconstexpr
Initial value:
=
has_vertex_descriptor< T >::value

Shorthand for has_vertex_descriptor<T>::value.

◆ is_array_like_v

template<typename T >
constexpr bool Utopia::Utils::is_array_like_v = is_array_like< T >::value
inlineconstexpr

Shorthand for is_array_like<T>::value.

◆ is_associative_container_v

template<typename T >
constexpr bool Utopia::Utils::is_associative_container_v
inlineconstexpr
Initial value:
=
is_associative_container< T >::value

Shorthand for is_associative_container<T>::value.

◆ is_callable_v

template<typename T >
constexpr bool Utopia::Utils::is_callable_v = is_callable< T >::value
constexpr

Shorthand for is_callable<T>::value.

◆ is_container_v

template<typename T >
constexpr bool Utopia::Utils::is_container_v = is_container< T >::value
inlineconstexpr

Shorthand for 'is_container::value.

◆ is_graph_v

template<typename T >
constexpr bool Utopia::Utils::is_graph_v = is_graph< T >::value
inlineconstexpr

Shorthand for is_graph<T>::value.

◆ is_iterable_v

template<typename T >
constexpr bool Utopia::Utils::is_iterable_v = is_iterable< T >::value
inlineconstexpr

shorthand for is_iterable<T>::value

◆ is_linear_container_v

template<typename T >
constexpr bool Utopia::Utils::is_linear_container_v = is_linear_container< T >::value
inlineconstexpr

Shorthand for is_linear_container<T>::value.

Template Parameters
Ttype to check

◆ is_random_access_container_v

template<typename T >
constexpr bool Utopia::Utils::is_random_access_container_v
inlineconstexpr
Initial value:
=
is_random_access_container< T >::value

shorthand for is_linear_container<T>::value

◆ is_string_v

template<typename T >
constexpr bool Utopia::Utils::is_string_v = is_string< T >::value
inlineconstexpr

Shorthand for 'is_string<T>::value'.

◆ is_unordered_associative_container_v

template<typename T >
constexpr bool Utopia::Utils::is_unordered_associative_container_v
inlineconstexpr
Initial value:
=
is_unordered_associative_container< T >::value

Shorthand for is_unordered_associative_container<T>::value.