argument_type Adaptable Unary Function The type of select2nd's argument: Pair
result_type Adaptable Unary Function The type of the result: Pair::second_type
const Pair::second_type& operator()(const Pair& p) const Adaptable Unary Function Function call. The return value is p.second.
New members

All of select2nd's members are defined in the Adaptable Unary Function requirements. Select2nd does not introduce any new members.

Notes

[1] Pair is not actually required to be a pair<U,V>, but merely to support the same interface as pair. In almost all cases the template parameter will be a pair, but it is occasionally useful for it to be something else. One example is a struct that has the members first, second, and third.

See also

identity, select1st, project1st, project2nd

subtractive_rng

Category: functors

Component type: type

Description

Subtractive_rng is a Random Number Generator based on the subtractive method [1]. It is a Unary Function: it takes a single argument N, an unsigned int, and returns an unsigned int that is less than N. Successive calls to the same subtractive_rng object [2] yield a pseudo-random sequence.

Example

int main() {

 subtractive_rng R;

 for (int i = 0; i < 20; ++i) cout << R(5) << ' ';

 cout << endl;

}

// The output is 3 2 3 2 4 3 1 1 2 2 0 3 4 4 4 4 2 1 0 0

Definition

Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h. This function object is an SGI extension; it is not part of the C++ standard.

Template parameters

None.

Model of

Random Number Generator, Adaptable Unary Function

Type requirements

None.

Public base classes

unary_function<unsigned int, unsigned int>

Members
Parameter Description Default
argument_type Adaptable Unary Function The type of a subtractive_rng's argument: unsigned int.
result_type Adaptable Unary Function The type of the result: unsigned int.
subtractive_rng(unsigned int seed) subtractive_rng See below.
subtractive_rng() subtractive_rng See below.
unsigned int operator()(unsigned int N) Adaptable Unary Function Function call. Returns a pseudo-random number in the range [0, N).
void initialize(unsigned int seed) subtractive_rng See below.
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату