dot-xx
A personal collection of small C++ modules
Loading...
Searching...
No Matches
dxx::utils Namespace Reference

The main namespace of the dxx::utils module. More...

Namespaces

namespace  heap
 The namespace for heap-allocated replacements for some standard library classes.

Classes

class  Defer
 Class for deferring operations until the end of lifetime. More...
class  FileDescriptor
 RAII file descriptor. Wraps an integer file descriptor and defers closing it to the desctructor. More...
struct  As

Concepts

concept  pointer
 Concept over std::is_pointer_v.
concept  reference
 Concept over std::is_reference_v.
concept  const_vrp
 A const value, a pointer to const, or a reference to const.
concept  mut_vrp
 Inverse of const_vrp.
concept  is_a
 Checks if the type is an instance of a template.
concept  either_of
 Checks if a type is the same as at least one of the provided arguments.
concept  neither_of
 Checks if a type is neither of provided arguments.
concept  declares
 Checks if the type was used to declare a certain value.

Functions

template<typename Integer>
constexpr auto range (const Integer &to)
 Python-like range function ([ 0, to )).
template<typename From, std::convertible_to< From > To>
constexpr auto range (const From &from, const To &to)
 Python-like range function ([ from, to )).
template<typename From, std::convertible_to< From > To, std::convertible_to< From > Step>
constexpr auto range (const From &from, const To &to, const Step &step)
 Python-like range function ([ from, to ) with step step).

Variables

template<typename T, typename... Ts>
constexpr std::optional< std::size_t > find_type_in = FindTypeIn<0, T, Ts...>::value
 Find the type T in the list of types Ts, return its index if present, otherwise is std::nullopt.
template<template< typename... > typename Range>
constexpr As< Range > as {}
 An adaptor-like shortcut to invoking an std::from_range constructor for a class template.

Detailed Description

The main namespace of the dxx::utils module.

Function Documentation

◆ range() [1/3]

template<typename From, std::convertible_to< From > To>
auto dxx::utils::range ( const From & from,
const To & to )
inlinenodiscardconstexprexport

Python-like range function ([ from, to )).

Returns
An appropriate std::views::iota view

◆ range() [2/3]

template<typename From, std::convertible_to< From > To, std::convertible_to< From > Step>
auto dxx::utils::range ( const From & from,
const To & to,
const Step & step )
inlinenodiscardconstexprexport

Python-like range function ([ from, to ) with step step).

Returns
An std::views::iota range transformed to have step step

◆ range() [3/3]

template<typename Integer>
auto dxx::utils::range ( const Integer & to)
inlinenodiscardconstexprexport

Python-like range function ([ 0, to )).

Returns
An appropriate std::views::iota view

Variable Documentation

◆ as

template<template< typename... > typename Range>
As<Range> dxx::utils::as {}
inlineconstexprexport

An adaptor-like shortcut to invoking an std::from_range constructor for a class template.

Does not work with regular types - use std::ranges::to or the constructor directly

E.g

auto v = range(10) | as<std::vector>;
constexpr As< Range > as
An adaptor-like shortcut to invoking an std::from_range constructor for a class template.
Definition ranges.xx:94
constexpr auto range(const Integer &to)
Python-like range function ([ 0, to )).
Definition ranges.xx:19

is the same as

std::vector v{ std::from_range, range(10) };

or

std::vector<int> v{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };