tgen
Loading...
Searching...
No Matches

Pair generator. More...

Inheritance diagram for tgen::pair< T >:

Classes

struct  value
 Pair value. More...

Public Member Functions

 pair (T first_left, T first_right, T second_left, T second_right)
 Creates pair generator defined by range of values for first and second.
 pair (T both_left, T both_right)
 Creates pair generator defined by range of values for both first and second.
paireq ()
 Restricts generator s.t. first is equal to second.
pairneq ()
 Restricts generator s.t. first is not equal to second.
pairlt ()
 Restricts generator s.t. first is less than second.
pairgt ()
 Restricts generator s.t. first is greater than second.
pairleq ()
 Restricts generator s.t. first is less than or equal to second.
pairgeq ()
 Restricts generator s.t. first is greater than or equal to second.
value gen () const
 Generates a random value from the set of valid pairs.
Public Member Functions inherited from tgen::gen_base< pair< T > >
auto gen_list (int size, Args &&...args) const
 Generates a list of several generation calls.
auto gen_until (Pred predicate, int max_tries, Args &&...args) const
 Generates a random value from the valid set until a condition is met.
auto distinct (Args &&...args) const
 Creates distinct generator for current generator.

Detailed Description

template<typename T>
struct tgen::pair< T >

Pair generator.

Defines a set of pairs, subject to restrictions.

A uniformly random tgen::pair::value from this set of pairs (that satisfies the restrictions) can be generated with tgen::pair::gen.

Definition at line 3471 of file tgen.h.

Constructor & Destructor Documentation

◆ pair() [1/2]

template<typename T>
tgen::pair< T >::pair ( T first_left,
T first_right,
T second_left,
T second_right )
inline

Creates pair generator defined by range of values for first and second.

Template Parameters
TIntegral type to be stored in the pair.
Parameters
first_leftLeft endpoint of value range for first.
first_rightRight endpoint of value range for first.
second_leftLeft endpoint of value range for second.
second_rightRight endpoint of value range for second.

Defines a generator of pairs with first in [first_left, first_right] and second in [second_left, second_right].

Examples

// Pairs of ints with first in [5, 10] and second in [10, 20].
auto pair_gen = tgen::pair<int>(5, 10, 10, 20);
Pair generator.
Definition tgen.h:3471

Definition at line 3479 of file tgen.h.

◆ pair() [2/2]

template<typename T>
tgen::pair< T >::pair ( T both_left,
T both_right )
inline

Creates pair generator defined by range of values for both first and second.

Template Parameters
TIntegral type to be stored in the pair.
Parameters
both_leftLeft endpoint of value range for first and second.
both_rightRight endpoint of value range for first and second;

Defines a generator of pairs with first in [both_left, both_right] and second in [both_left, both_right].

Equivalent to tgen::pair::pair(both_left, both_right, both_left, borh_right).

Examples

// Pairs of ints with values in [10, 20].
auto pair_gen = tgen::pair<int>(10, 20);

Definition at line 3488 of file tgen.h.

Member Function Documentation

◆ eq()

template<typename T>
pair & tgen::pair< T >::eq ( )
inline

Restricts generator s.t. first is equal to second.

Examples

// Pairs of values in [10, 20] with first = second.
auto pair_gen = tgen::pair<int>(10, 20).eq();
pair & eq()
Restricts generator s.t. first is equal to second.
Definition tgen.h:3492

Definition at line 3492 of file tgen.h.

◆ gen()

template<typename T>
value tgen::pair< T >::gen ( ) const
inline

Generates a random value from the set of valid pairs.

Returns
A uniformly random tgen::pair::value from the set of valid pairs, given the added restrictions.
Exceptions
std::runtime_errorif there is no valid pair satisfying all added restrictions.

Complexity

O(log(first_right - first_left) + log(second_right - second_left)).

Examples

// Generates and prints a random pair of values in [10, 20] with first <= second.
auto inst = tgen::pair<int>(10, 20).leq().gen();
std::cout << inst << std::endl;
value gen() const
Generates a random value from the set of valid pairs.
Definition tgen.h:3567
pair & leq()
Restricts generator s.t. first is less than or equal to second.
Definition tgen.h:3516

Definition at line 3567 of file tgen.h.

◆ geq()

template<typename T>
pair & tgen::pair< T >::geq ( )
inline

Restricts generator s.t. first is greater than or equal to second.

Examples

// Pairs of values in [10, 20] with first >= second.
auto pair_gen = tgen::pair<int>(10, 20).geq();
pair & geq()
Restricts generator s.t. first is greater than or equal to second.
Definition tgen.h:3522

Definition at line 3522 of file tgen.h.

◆ gt()

template<typename T>
pair & tgen::pair< T >::gt ( )
inline

Restricts generator s.t. first is greater than second.

Examples

// Pairs of values in [10, 20] with first > second.
auto pair_gen = tgen::pair<int>(10, 20).gt();
pair & gt()
Restricts generator s.t. first is greater than second.
Definition tgen.h:3510

Definition at line 3510 of file tgen.h.

◆ leq()

template<typename T>
pair & tgen::pair< T >::leq ( )
inline

Restricts generator s.t. first is less than or equal to second.

Examples

// Pairs of values in [10, 20] with first <= second.
auto pair_gen = tgen::pair<int>(10, 20).leq();

Definition at line 3516 of file tgen.h.

◆ lt()

template<typename T>
pair & tgen::pair< T >::lt ( )
inline

Restricts generator s.t. first is less than second.

Examples

// Pairs of values in [10, 20] with first < second.
auto pair_gen = tgen::pair<int>(10, 20).lt();
pair & lt()
Restricts generator s.t. first is less than second.
Definition tgen.h:3504

Definition at line 3504 of file tgen.h.

◆ neq()

template<typename T>
pair & tgen::pair< T >::neq ( )
inline

Restricts generator s.t. first is not equal to second.

Examples

// Pairs of values in [10, 20] with first = second.
auto pair_gen = tgen::pair<int>(10, 20).neq();
pair & neq()
Restricts generator s.t. first is not equal to second.
Definition tgen.h:3498

Definition at line 3498 of file tgen.h.


The documentation for this struct was generated from the following files:
  • /home/runner/work/tgen/tgen/single_include/tgen.h
  • pair.dox