tgen 1.4.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.
pair & eq ()
 Restricts generator s.t. first is equal to second.
pair & neq ()
 Restricts generator s.t. first is not equal to second.
pair & lt ()
 Restricts generator s.t. first is less than second.
pair & gt ()
 Restricts generator s.t. first is greater than second.
pair & leq ()
 Restricts generator s.t. first is less than or equal to second.
pair & geq ()
 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 4187 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:4187

Definition at line 4195 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 4204 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:4208

Definition at line 4208 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.

Time 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:4283
pair & leq()
Restricts generator s.t. first is less than or equal to second.
Definition tgen.h:4232

Definition at line 4283 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:4238

Definition at line 4238 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:4226

Definition at line 4226 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 4232 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:4220

Definition at line 4220 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:4214

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