Skip to content

Commit

Permalink
Change ulong to size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-zherikov committed Jul 11, 2024
1 parent 47d4204 commit dafa8f0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions docs/topics/Arity.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Sometimes an argument might accept more than one value. This is especially a cas
- Unlimited range where only minimum number of values is provided (e.g. argument accepts _any number_ of values).

To adjust the arity, use one the following API:
- `NumberOfValues(ulong min, ulong max)` – sets both minimum and maximum number of values.
- `NumberOfValues(ulong num)` – sets the exact number of values.
- `MinNumberOfValues(ulong min)` – sets minimum number of values.
- `MaxNumberOfValues(ulong max)` – sets maximum number of values.
- `NumberOfValues(size_t min, size_t max)` – sets both minimum and maximum number of values.
- `NumberOfValues(size_t num)` – sets the exact number of values.
- `MinNumberOfValues(size_t min)` – sets minimum number of values.
- `MaxNumberOfValues(size_t max)` – sets maximum number of values.

> Positional argument must have at least one value.
>
Expand Down
8 changes: 4 additions & 4 deletions docs/topics/reference/PositionalNamedArgument.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ struct my_command
**Signature**
```C++
NumberOfValues(auto ref ... argument, ulong min, ulong max)
NumberOfValues(auto ref ... argument, ulong num)
NumberOfValues(auto ref ... argument, size_t min, size_t max)
NumberOfValues(auto ref ... argument, size_t num)
```

**Parameters**
Expand Down Expand Up @@ -198,7 +198,7 @@ struct my_command
**Signature**
```C++
MinNumberOfValues(auto ref ... argument, ulong min)
MinNumberOfValues(auto ref ... argument, size_t min)
```

**Parameters**
Expand All @@ -224,7 +224,7 @@ struct my_command
**Signature**
```C++
MaxNumberOfValues(auto ref ... argument, ulong max)
MaxNumberOfValues(auto ref ... argument, size_t max)
```

**Parameters**
Expand Down
14 changes: 7 additions & 7 deletions source/argparse/api/argument.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,29 @@ auto ref Placeholder(T)(auto ref ArgumentUDA!T uda, string value)
return uda;
}

auto ref NumberOfValues(T)(auto ref ArgumentUDA!T uda, ulong num)
auto ref NumberOfValues(T)(auto ref ArgumentUDA!T uda, size_t num)
{
uda.info.minValuesCount = num;
uda.info.maxValuesCount = num;
return uda;
}

auto ref NumberOfValues(T)(auto ref ArgumentUDA!T uda, ulong min, ulong max)
auto ref NumberOfValues(T)(auto ref ArgumentUDA!T uda, size_t min, size_t max)
{
uda.info.minValuesCount = min;
uda.info.maxValuesCount = max;
return uda;
}

auto ref MinNumberOfValues(T)(auto ref ArgumentUDA!T uda, ulong min)
auto ref MinNumberOfValues(T)(auto ref ArgumentUDA!T uda, size_t min)
{
assert(min <= uda.info.maxValuesCount.get(ulong.max));
assert(min <= uda.info.maxValuesCount.get(size_t.max));

uda.info.minValuesCount = min;
return uda;
}

auto ref MaxNumberOfValues(T)(auto ref ArgumentUDA!T uda, ulong max)
auto ref MaxNumberOfValues(T)(auto ref ArgumentUDA!T uda, size_t max)
{
assert(max >= uda.info.minValuesCount.get(0));

Expand Down Expand Up @@ -221,7 +221,7 @@ auto Parse(alias func, T)(ArgumentUDA!T uda)
else
{
desc.info.minValuesCount = 0;
desc.info.maxValuesCount = ulong.max;
desc.info.maxValuesCount = size_t.max;
}

return desc;
Expand Down Expand Up @@ -274,7 +274,7 @@ unittest
assert(is(typeof(uda) : ArgumentUDA!(ValueParser!(void, void, FUNC, void, void, void)), alias FUNC));
assert(!is(FUNC == void));
assert(uda.info.minValuesCount == 0);
assert(uda.info.maxValuesCount == ulong.max);
assert(uda.info.maxValuesCount == size_t.max);
}

unittest
Expand Down
6 changes: 3 additions & 3 deletions source/argparse/internal/arguments.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ package(argparse) struct ArgumentInfo

bool positional() const { return !position.isNull; }

Nullable!ulong minValuesCount;
Nullable!ulong maxValuesCount;
Nullable!size_t minValuesCount;
Nullable!size_t maxValuesCount;

auto checkValuesCount(const Config config, string argName, ulong count) const
auto checkValuesCount(const Config config, string argName, size_t count) const
{
immutable min = minValuesCount.get;
immutable max = maxValuesCount.get;
Expand Down
6 changes: 3 additions & 3 deletions source/argparse/internal/argumentudahelpers.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private template defaultValuesCount(T)
else static if(isArray!T || isAssociativeArray!T)
{
enum min = 1;
enum max = ulong.max;
enum max = size_t.max;
}
else static if(is(T == function))
{
Expand All @@ -50,13 +50,13 @@ private template defaultValuesCount(T)
else static if(__traits(compiles, T([string.init])))
{
enum min = 0;
enum max = ulong.max;
enum max = size_t.max;
}
// ... function(RawParam param)
else static if(__traits(compiles, T(RawParam.init)))
{
enum min = 1;
enum max = ulong.max;
enum max = size_t.max;
}
else
static assert(false, "Unsupported callback: " ~ T.stringof);
Expand Down
6 changes: 3 additions & 3 deletions source/argparse/internal/help.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ package struct Section
return title.length == 0 || entries.match!(_ => _.length) == 0;
}

private ulong maxItemNameLength(ulong limit) const
private size_t maxItemNameLength(size_t limit) const
{
import std.algorithm: maxElement, map, filter;

Expand Down Expand Up @@ -236,7 +236,7 @@ unittest

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private string spaces(ulong num)
private string spaces(size_t num)
{
import std.range: repeat;
import std.array: array;
Expand Down Expand Up @@ -547,7 +547,7 @@ private auto getSections(const ref Style style, const(Arguments*)[] arguments)
foreach(ref group; chain(args.userGroups, [args.requiredGroup, args.optionalGroup]))
{
auto p = (group.name in sectionMap);
ulong index;
size_t index;
if(p !is null)
index = *p;
else
Expand Down
2 changes: 1 addition & 1 deletion source/argparse/internal/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import argparse.internal.commandinfo: getTopLevelCommandInfo;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private string[] consumeValuesFromCLI(ref string[] args,
ulong minValuesCount, ulong maxValuesCount,
size_t minValuesCount, size_t maxValuesCount,
bool delegate(string) isArgumentValue)
{
import std.range: empty, front, popFront;
Expand Down

0 comments on commit dafa8f0

Please sign in to comment.