arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::utility Namespace Reference

Namespaces

 string_to_policy
 
 string_view_ops
 
 terminal
 
 utf8
 

Classes

class  compile_time_optional
 
class  compile_time_string
 
class  create_sequence_cts
 
struct  convert_to_cts
 
struct  convert_integral_to_cts
 
class  dynamic_string_view
 
class  exception_formatter
 
class  result
 
struct  tree_type_recursor_collector
 
class  unsafe_any_t
 

Typedefs

template<std::size_t N, char C>
using create_sequence_cts_t = typename create_sequence_cts< N, C >::type
 
template<typename T >
using convert_to_cts_t = typename convert_to_cts< T >::type
 
template<auto Value>
using convert_integral_to_cts_t = typename convert_integral_to_cts< Value >::type
 
template<template< typename... > typename Visitor, typename Root >
using tree_type_recursor_collector_t = typename tree_type_recursor_collector< Visitor, Root >::type
 
using unsafe_any = unsafe_any_t< sizeof(std::string_view)>
 

Functions

std::ostream & operator<< (std::ostream &stream, const dynamic_string_view &dsv)
 
template<typename T >
dynamic_string_view operator+ (dynamic_string_view a, T &&b)
 
template<typename Visitor , typename Root >
constexpr void tree_recursor (Visitor visitor, const Root &root)
 
template<typename Visitor , typename SkipFn , typename Root >
constexpr void tree_type_recursor ()
 
template<typename Visitor , typename Root >
constexpr void tree_type_recursor ()
 
template<typename F , typename Tuple >
constexpr std::enable_if_t< traits::is_tuple_like_v< std::decay_t< Tuple > > > tuple_iterator (F &&f, Tuple &&tuple)
 
template<typename F , typename... T>
constexpr void tuple_iterator (F &&f, T &&... pack)
 
template<typename Tuple , typename F >
constexpr std::enable_if_t< traits::is_tuple_like_v< std::decay_t< Tuple > > > tuple_type_iterator (F &&f)
 
template<typename T >
std::size_t type_hash () noexcept
 

Detailed Description

Namespace for utility types and functions.

Typedef Documentation

◆ convert_integral_to_cts_t

template<auto Value>
using arg_router::utility::convert_integral_to_cts_t = typedef typename convert_integral_to_cts<Value>::type

Helper alias for convert_integral_to_cts.

Template Parameters
ValueIntegral to convert

Definition at line 483 of file compile_time_string.hpp.

◆ convert_to_cts_t

template<typename T >
using arg_router::utility::convert_to_cts_t = typedef typename convert_to_cts<T>::type

Helper alias

Template Parameters
TChar integral constant array-like type

Definition at line 442 of file compile_time_string.hpp.

◆ create_sequence_cts_t

template<std::size_t N, char C>
using arg_router::utility::create_sequence_cts_t = typedef typename create_sequence_cts<N, C>::type

Helper alias for create_sequence_cts.

Template Parameters
NNumber of times to repeat C
CCharacter to repeat

Definition at line 423 of file compile_time_string.hpp.

◆ tree_type_recursor_collector_t

template<template< typename... > typename Visitor, typename Root >
using arg_router::utility::tree_type_recursor_collector_t = typedef typename tree_type_recursor_collector<Visitor, Root>::type

Helper alias for tree_type_recursor_collector.

Template Parameters
VisitorVisitor object type
RootStart object type in the parse tree

Definition at line 188 of file tree_recursor.hpp.

◆ unsafe_any

using arg_router::utility::unsafe_any = typedef unsafe_any_t<sizeof(std::string_view)>

Typedef for an unsafe_any_t with internal storage big enough to fit a std::string_view.

Definition at line 210 of file unsafe_any.hpp.

Function Documentation

◆ operator+()

template<typename T >
dynamic_string_view arg_router::utility::operator+ ( dynamic_string_view  a,
T &&  b 
)
inline

Concatenation operator.

Copies a and then b into internal storage and updates the view to match.

Template Parameters
TType of a
Parameters
adynamic_string_view instance
bString-like type
Returns
dynamic_string_view consisting of a with b appended

Definition at line 211 of file dynamic_string_view.hpp.

◆ operator<<()

std::ostream& arg_router::utility::operator<< ( std::ostream &  stream,
const dynamic_string_view dsv 
)
inline

Textual streaming operator.

Parameters
streamOutput stream
dsvInstance
Returns
stream

Definition at line 197 of file dynamic_string_view.hpp.

◆ tree_recursor()

template<typename Visitor , typename Root >
constexpr void arg_router::utility::tree_recursor ( Visitor  visitor,
const Root &  root 
)
constexpr

Depth-first search of the node tree, calling visitor on every tree_node.

Visitor must be a Callable with the same method signatue as below:

template <typename Current, typename... Parents>
void operator()(const Current& current, const Parents&... parents)
{
...
}

Where current is the current node from the tree, and parents is a pack of ancestors in increasing generation from current. The last in the pack is always root.

Template Parameters
VisitorVisitor type
Roottree_node derived type to start from
Parameters
visitorCallable called on each tree_node visited
rootTree node to start from (must be a tree_node derived type!)

Definition at line 102 of file tree_recursor.hpp.

◆ tree_type_recursor() [1/2]

template<typename Visitor , typename SkipFn , typename Root >
constexpr void arg_router::utility::tree_type_recursor ( )
constexpr

Depth-first recurse through the parse tree, calling Visitor on every tree_node and its policies.

Visitor must be object with the same method signatue as below:

struct my_fn {
template <typename Current, typename... Parents>
constexpr static void fn()
{
...
}
};

Where Current is the current type from the tree, and Parents is a pack of ancestors in increasing generation from Current. The last in the pack is always the root.

SkipFn must be object with the same method signatue as below:

struct my_skip_fn {
template <typename Current, typename... Parents>
constexpr static bool fn()
{
...
return condition_met;
}
};

If the return value is true, then the Current node or policy and any subtree below it are skipped i.e. fn is not called.

Note
Unlike tree_recursor(Visitor visitor, const Root& root), this will recurse into tree_node policies.
Template Parameters
VisitorVisitor type
SkipFnSkip function type
RootStart object type in the parse tree

Definition at line 145 of file tree_recursor.hpp.

◆ tree_type_recursor() [2/2]

template<typename Visitor , typename Root >
constexpr void arg_router::utility::tree_type_recursor ( )
constexpr

Overload without a skip function.

Template Parameters
VisitorVisitor type
RootStart object type in the parse tree

Definition at line 156 of file tree_recursor.hpp.

◆ tuple_iterator() [1/2]

template<typename F , typename... T>
constexpr void arg_router::utility::tuple_iterator ( F &&  f,
T &&...  pack 
)
constexpr

Iterates over pack and calls f on each instance within it.

Forwards pack into a tuple and uses it to call tuple_iterator(F&&, Tuple&&).

Template Parameters
FCallable type
TPack types
Parameters
fCallable instance
packInstances to iterate over

Definition at line 50 of file tuple_iterator.hpp.

◆ tuple_iterator() [2/2]

template<typename F , typename Tuple >
constexpr std::enable_if_t<traits::is_tuple_like_v<std::decay_t<Tuple> > > arg_router::utility::tuple_iterator ( F &&  f,
Tuple &&  tuple 
)
constexpr

Iterates over tuple and calls f on each element.

auto t = std::tuple{"hello"s, 42.5, 9};
tuple_iterator([](auto i, auto&& v) {
std::cout << i << ": " << v << std::endl;
}, t);
// 0: hello
// 1: 42.5
// 2: 9
constexpr std::enable_if_t< traits::is_tuple_like_v< std::decay_t< Tuple > > > tuple_iterator(F &&f, Tuple &&tuple)
Template Parameters
FCallable type
TupleTuple type
Parameters
fCallable instance
tupleTuple instance
Returns
Void

Definition at line 33 of file tuple_iterator.hpp.

◆ tuple_type_iterator()

template<typename Tuple , typename F >
constexpr std::enable_if_t<traits::is_tuple_like_v<std::decay_t<Tuple> > > arg_router::utility::tuple_type_iterator ( F &&  f)
constexpr

Iterates over tuple and passes a nullptr pointer of the tuple element to f.

using Tuple = std::tuple<std::string, double, int>;
tuple_type_iterator<Tuple>([](auto i) {
using Arg = std::tuple_element_t<i, Tuple>;
std::cout << i << ": " << boost::core::demangle(typeid(Arg).name())
<< std::endl;
});
// 0: std::string
// 1: double
// 2: int
Template Parameters
TupleTuple type
FCallable type
Parameters
fCallable instance
Returns
Void

Definition at line 75 of file tuple_iterator.hpp.

◆ type_hash()

template<typename T >
std::size_t arg_router::utility::type_hash ( )
noexcept

Hash generation for a type.

This is intended to replace typeid(T).hash_code(), as the use of typeid causes huge amounts of class name data to be put into the binary's static data storage - which isn't used!

Note
Aliases are resolved by the compiler in a pre-processing stage before this, so type_hash<std::uint64_t>() == type_hash<unsigned long>() (on a 64bit system)

Anyone reading the implementation will see that this is not a hash function, it just takes the address of the instantiated function. Originally this used the hash of the PRETTY_FUNCTION output and therefore could be used at compile-time. Unfortunately that was ruined when C++20 compile-time string support was added, due to a bug in gcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108269) which produced incorrect output when std::array was used inside an NTTP.

Parameters
TType to generate a hash code for
Returns
Hash code of T

Definition at line 29 of file type_hash.hpp.