Function gen_const

Source
pub fn gen_const<const N: usize>() -> impl DoubleEndedIterator<Item = [bool; N]> + ExactSizeIterator + FusedIterator
Expand description

Returns an Iterator producing all possible combinations of [bool; N].

See also gen() for non-const generic variant.

See also implementation for more information about the Iterator implementation.

§Panics

Panics if N is larger than the MAX number of supported variables. However, you likely have other problems, if you encounter this.

See also count(N) and is_supported(N).

§Example

See crate root for more examples.

let combinations = truth_values::gen_const()
    .map(|[a, b]| {
        (a, b)
    })
    .collect::<Vec<_>>();

assert_eq!(
    combinations,
    [
        (false, false),
        (true, false),
        (false, true),
        (true, true),
    ]
);
Examples found in repository?
examples/example.rs (line 45)
38fn main() {
39    truth_values::each_const(|[a, b]| {
40        assert_eq!(!(a || b), !a && !b);
41        assert_eq!(!(a && b), !a || !b);
42    });
43
44    let mut exprs = Vec::new();
45    exprs.extend(truth_values::gen_const().map(|[a, b]| {
46        let x = not(or(a, b));
47        let y = and(not(a), not(b));
48        (x, y)
49    }));
50    exprs.extend(truth_values::gen_const().map(|[a, b]| {
51        let x = not(and(a, b));
52        let y = or(not(a), not(b));
53        (x, y)
54    }));
55
56    for (x, y) in exprs {
57        println!("{} = {:?}", x.eval(), x);
58        println!("{} = {:?}", y.eval(), y);
59        println!();
60
61        assert_eq!(x.eval(), y.eval());
62    }
63}