CPP-AP 2.7.0
Command-line argument parser for C++20
Loading...
Searching...
No Matches
ap::nargs::range Class Reference

Argument's number of values managing class. More...

#include <range.hpp>

Public Types

using count_type = std::size_t
 

Public Member Functions

 range ()
 Default constructor: creates range [1, 1].
 
 range (const count_type n)
 Exact count constructor: creates range [n, n].
 
 range (const count_type lower_bound, const count_type upper_bound)
 Concrete range constructor: creates range [lower_bound, upper_bound].
 
 range (const range &)=default
 
 range (range &&)=default
 
rangeoperator= (const range &)=default
 
rangeoperator= (range &&)=default
 
 ~range ()=default
 
bool is_bound () const noexcept
 Returns true if at least one bound (lower, upper) is set. Otherwise returns false
 
std::weak_ordering ordering (const range::count_type n) const noexcept
 Determines the ordering of the count against a range instance.
 

Private Member Functions

 range (const std::optional< count_type > lower_bound, const std::optional< count_type > upper_bound)
 Private constructor: creates a possibly unbound range.
 

Private Attributes

std::optional< count_type_lower_bound
 
std::optional< count_type_upper_bound
 

Static Private Attributes

static constexpr count_type _default_bound = 1ull
 

Friends

std::ostream & operator<< (std::ostream &os, const range &r) noexcept
 
range at_least (const count_type) noexcept
 range class builder function. Creates a range [n, inf].
 
range more_than (const count_type) noexcept
 range class builder function. Creates a range [n + 1, inf].
 
range less_than (const count_type) noexcept
 range class builder function. Creates a range [0, n - 1].
 
range up_to (const count_type) noexcept
 range class builder function. Creates a range [0, n].
 
range any () noexcept
 range class builder function. Creates a range [0, inf].
 

Detailed Description

Argument's number of values managing class.

Definition at line 18 of file range.hpp.

Member Typedef Documentation

◆ count_type

using ap::nargs::range::count_type = std::size_t

Definition at line 20 of file range.hpp.

Constructor & Destructor Documentation

◆ range() [1/6]

ap::nargs::range::range ( )
inline

Default constructor: creates range [1, 1].

Definition at line 23 of file range.hpp.

◆ range() [2/6]

ap::nargs::range::range ( const count_type  n)
inlineexplicit

Exact count constructor: creates range [n, n].

Parameters
nExpected value count.

Definition at line 29 of file range.hpp.

◆ range() [3/6]

ap::nargs::range::range ( const count_type  lower_bound,
const count_type  upper_bound 
)
inline

Concrete range constructor: creates range [lower_bound, upper_bound].

Parameters
lower_boundThe lower bound.
upper_boundThe upper bound.

Definition at line 36 of file range.hpp.

◆ range() [4/6]

ap::nargs::range::range ( const range )
default

◆ range() [5/6]

ap::nargs::range::range ( range &&  )
default

◆ ~range()

ap::nargs::range::~range ( )
default

◆ range() [6/6]

ap::nargs::range::range ( const std::optional< count_type lower_bound,
const std::optional< count_type upper_bound 
)
inlineprivate

Private constructor: creates a possibly unbound range.

Parameters
lower_boundThe optional lower bound of the range.
upper_boundThe optional upper bound of the range.

Definition at line 121 of file range.hpp.

Member Function Documentation

◆ is_bound()

bool ap::nargs::range::is_bound ( ) const
inlinenoexcept

Returns true if at least one bound (lower, upper) is set. Otherwise returns false

Definition at line 48 of file range.hpp.

◆ operator=() [1/2]

range & ap::nargs::range::operator= ( const range )
default

◆ operator=() [2/2]

range & ap::nargs::range::operator= ( range &&  )
default

◆ ordering()

std::weak_ordering ap::nargs::range::ordering ( const range::count_type  n) const
inlinenoexcept

Determines the ordering of the count against a range instance.

For a [lower, upper] range and the count n the returned value is:

  • less if n < lower,
  • equivalent if n >= lower and n <= upper,
  • greater if n > upper. If either lower or upper limits are not set (std::nullopt), then the corresponding conditions are dropped.
Parameters
nThe value count to order.
Returns
Ordering relationship between the count and the range.

Definition at line 65 of file range.hpp.

Friends And Related Symbol Documentation

◆ any

range any ( )
friend

range class builder function. Creates a range [0, inf].

Returns
Built range class instance.

Definition at line 170 of file range.hpp.

◆ at_least

range at_least ( const count_type  n)
friend

range class builder function. Creates a range [n, inf].

Parameters
nThe lower bound.
Returns
Built range class instance.

Definition at line 135 of file range.hpp.

◆ less_than

range less_than ( const count_type  n)
friend

range class builder function. Creates a range [0, n - 1].

Parameters
nThe upper bound
Returns
Built range class instance.

Definition at line 153 of file range.hpp.

◆ more_than

range more_than ( const count_type  n)
friend

range class builder function. Creates a range [n + 1, inf].

Parameters
nThe lower bound.
Returns
Built range class instance.

Definition at line 144 of file range.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const range r 
)
friend

Definition at line 89 of file range.hpp.

◆ up_to

range up_to ( const count_type  n)
friend

range class builder function. Creates a range [0, n].

Parameters
nThe upper bound
Returns
Built range class instance.

Definition at line 162 of file range.hpp.

Member Data Documentation

◆ _default_bound

constexpr count_type ap::nargs::range::_default_bound = 1ull
staticconstexprprivate

Definition at line 127 of file range.hpp.

◆ _lower_bound

std::optional<count_type> ap::nargs::range::_lower_bound
private

Definition at line 124 of file range.hpp.

◆ _upper_bound

std::optional<count_type> ap::nargs::range::_upper_bound
private

Definition at line 125 of file range.hpp.


The documentation for this class was generated from the following file: