tgen 1.1.0
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 uniformly 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 4139 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:4139

Definition at line 4147 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, both_right).

Examples

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

Definition at line 4156 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:4160

Definition at line 4160 of file tgen.h.

◆ gen()

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

Generates a uniformly 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 val = tgen::pair<int>(10, 20).leq().gen();
std::cout << val << std::endl;
value gen() const
Generates a uniformly random value from the set of valid pairs.
Definition tgen.h:4235
pair & leq()
Restricts generator s.t. first is less than or equal to second.
Definition tgen.h:4184

Definition at line 4235 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:4190

Definition at line 4190 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:4178

Definition at line 4178 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 4184 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:4172

Definition at line 4172 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:4166

Definition at line 4166 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