File: size_validation.md

package info (click to toggle)
reflect-cpp 0.18.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,524 kB
  • sloc: cpp: 44,484; python: 131; makefile: 30; sh: 3
file content (18 lines) | stat: -rw-r--r-- 580 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# `rfl::Size`

`rfl::Size` can be used to impose constraints on any container that contains the method `.size()`, which includes `std::string`.

For instance, you can a require a vector to be non-empty as follows:

```cpp
using NonEmptyStringVector =
    rfl::Validator<std::vector<std::string>, rfl::Size<rfl::Minimum<1>>>;
```

Or you could require it to contain exactly zero or three elements, using validator composition:

```cpp
using NoneOrThree =
    rfl::Validator<std::vector<std::string>,
                   rfl::Size<rfl::AnyOf<rfl::EqualTo<0>, rfl::EqualTo<3>>>>;
```