CPP-AP 3.0.1
Command-line argument parser for C++20
Loading...
Searching...
No Matches
Utility

Helper functions, types, concepts, etc. More...

Concepts

concept  ap::action::util::c_value_action_specifier
 The concept is satisfied when AS is a valid value action action specifier.
 
concept  ap::action::util::c_flag_action_specifier
 The concept is satisfied when AS is a valid on-flag action action specifier.
 
concept  ap::action::util::c_action_specifier
 The concept is satisfied when AS is a valid action action specifier.
 
concept  ap::util::c_is_none
 The concept is satisfied when T is ap::none_type.
 
concept  ap::util::c_readable
 The concept is satisfied when T overloads the std::istream operator >>.
 
concept  ap::util::c_trivially_readable
 The concept is satisfied when T can be constructed from const std::string&.
 
concept  ap::util::c_writable
 The concept is satisfied when T overloads the std::ostream operator <<.
 
concept  ap::util::c_arithmetic
 The concept is satisfied when T is an arithmetic type.
 
concept  ap::util::c_argument_value_type
 The concept is used to verify the validity of the arguments' value types.
 
concept  ap::util::c_one_of
 Validates that T is the same as one of the types defined by Types.
 
concept  ap::util::c_valid_type
 Concept that enforces is_valid_type_v.
 
concept  ap::util::c_range_of
 Validates that R is a range of type T (ignoring the cvref qualifiers).
 
concept  ap::util::c_forward_range_of
 Validates that It is a forward iterator of type T (ignoring the cvref qualifiers).
 
concept  ap::util::c_forward_iterator_of
 Validates that It is a forward iterator of type T (ignoring the cvref qualifiers).
 

Classes

struct  ap::action::util::apply_visitor< T >
 A visitor structure used to apply value actions. More...
 

Typedefs

template<c_value_action_specifier AS, ap::util::c_argument_value_type T>
using ap::action::util::callable_type = typename AS::template type< T >
 Template argument action callable type alias.
 

Enumerations

enum class  ap::util::type_validator : bool { ap::util::type_validator::same , ap::util::type_validator::convertible }
 Specifies the type validation rule. More...
 

Functions

template<typename T >
auto ap::util::any_range_cast_view (const c_range_of< std::any > auto &range)
 Casts a range of std::any to a range of type T.
 
template<c_writable T>
std::string ap::util::as_string (const T &value) noexcept
 Converts a value to std::string.
 
template<std::ranges::range R>
requires (c_writable<std::ranges::range_value_t<R>>)
std::string ap::util::join (const R &range, const std::string_view delimiter=", ")
 Joins elements of a range into a single string with a delimiter.
 
template<typename T >
constexpr std::string_view ap::util::get_demangled_type_name ()
 Retrieves the demangled name of a type T.
 

Variables

template<typename T , typename U , type_validator TV>
constexpr bool ap::util::is_valid_type_v = false
 Checks if two types satisfy a given type_validator rule.
 

Detailed Description

Helper functions, types, concepts, etc.

Typedef Documentation

◆ callable_type

template<c_value_action_specifier AS, ap::util::c_argument_value_type T>
using ap::action::util::callable_type = typedef typename AS::template type<T>

Template argument action callable type alias.

Definition at line 22 of file helpers.hpp.

Enumeration Type Documentation

◆ type_validator

enum class ap::util::type_validator : bool
strong

Specifies the type validation rule.

Enumerator
same 

Exact type match.

convertible 

Implicit conversion allowed.

Definition at line 82 of file concepts.hpp.

Function Documentation

◆ any_range_cast_view()

template<typename T >
auto ap::util::any_range_cast_view ( const c_range_of< std::any > auto &  range)

Casts a range of std::any to a range of type T.

Template Parameters
TThe target type.
Parameters
rangeThe input range of std::any.
Returns
A view representing the casted range of type T.
Exceptions
std::bad_any_castif any element in the input range cannot be cast to type T.

Definition at line 28 of file ranges.hpp.

◆ as_string()

template<c_writable T>
std::string ap::util::as_string ( const T &  value)
noexcept

Converts a value to std::string.

Template Parameters
TThe value type (must satisfy the ap::util::c_writable concept).
Parameters
valueThe value to convert.

Definition at line 27 of file string.hpp.

◆ get_demangled_type_name()

template<typename T >
constexpr std::string_view ap::util::get_demangled_type_name ( )
constexpr

Retrieves the demangled name of a type T.

Template Parameters
TThe type to retrieve the name for.
Returns
A string view representing the demangled name of type T.
Note
- The function uses compiler-specific macros to extract the type name.
- Supported compilers: GCC, Clang, MSVC.

Definition at line 29 of file typing.hpp.

◆ join()

template<std::ranges::range R>
requires (c_writable<std::ranges::range_value_t<R>>)
std::string ap::util::join ( const R &  range,
const std::string_view  delimiter = ", " 
)

Joins elements of a range into a single string with a delimiter.

Template Parameters
RThe type of the value range. The value type of R must satisfy the c_writable concept.
Parameters
rangeThe input range to join.
delimiterThe separator string to insert between elements.
Returns
A single string with all elements joined by the delimiter.
Todo:
Replace with std::views::join after transition to C++23.
Examples
/home/runner/work/cpp-ap/cpp-ap/include/ap/argument_parser.hpp.

Definition at line 49 of file string.hpp.

Variable Documentation

◆ is_valid_type_v

template<typename T , typename U , type_validator TV>
constexpr bool ap::util::is_valid_type_v = false
inlineconstexpr

Checks if two types satisfy a given type_validator rule.

The primary template of the is_valid_type_v helper variable, which does not perform any logic and defaults to false.

Template Parameters
TThe type to check.
UThe type to check agains.
TVThe validation rule.

Definition at line 99 of file concepts.hpp.