Standard Template Library Programmer's Guide

Здесь есть возможность читать онлайн «Standard Template Library Programmer's Guide» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, Справочники, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Standard Template Library Programmer's Guide: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Standard Template Library Programmer's Guide»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

This document contains reference on SGI STL implementation

Standard Template Library Programmer's Guide — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Standard Template Library Programmer's Guide», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать
See also

LessThan Comparable, less , Binary Predicate, function objects

MonoidOperation

Category: functors

Component type: concept

Description

A Monoid Operation is a special sort of Binary Function. A Binary Function must satisfy three conditions in order to be a Monoid Operation. First, its first argument type and second argument type must be the same, and its result type must be the same as its argument type. Second, there must be an identity element. Third, the operation must be associative. Examples of Monoid Operations are addition and multiplication. [1]

Refinement of

Binary Function

Associated types
Argument type The type of the Monoid Operation's first argument and second argument, and also the type returned when the Monoid Operation is returned.
Notation

FA type that is a model of MonoidOperation

T F 's argument type.

fObject of type F

x, y, zObjects of type T

Definitions

A type F that is a model of binary function is associative if F 's first argument type, second argument type, and result type are the same, and if, for every object f of type F and for every objects x , y , and z of F 's argument type, f(x, f(y, z)) is the same as f(f(x, y), z) . [2]

Valid Expressions

In addition to the expressions described in the Binary Function requirements, the following expressions must be valid.

Name Expression Return type
Function call f(x, y) T
Identity element identity_element(f)[3] T
Expression semantics
Name Expression Precondition Semantics
Function call f(x, y) x and y are in the domain of f . Calls f with x and y as arguments.
Identity element identity_element(f) Returns the monoid's identity element. That is, the return value is a value id of type T such that, for all x in the domain of f , f(x, id) and f(id, x) both return x .
Invariants
Associativity For any x , y , and z of type T , f(x, f(y, z)) and f(f(x, y), z) return the same value. [4]
Identity element. There exists some element id of type T such that, for all x of type T , f(x, id) and f(id, x) both return x . The expression identity_element(f) returns id .
Models

• plus

• multiplies

Notes

[1] A monoid is one of three closely related algebraic structures. A semigroup is a set S, and a binary operation *, with the properties that * is closed on S (that is, if x and y are elements of S then x * y is also a member of S) and that * is associative (that is, if x, y, and z are elements of S, then x * (y * z) = (x * y) * z). A monoid is a semigroup that has an identity element. That is, there exists some element id such that, for all x in S, x * id = id * x = x. Finally, a group is a monoid with the property that every element has an inverse. That is, for every x in S, there exists an element xi such that x * xi = xi * x = id. As an example, the set of real numbers under multiplication is a monoid (the identity element is 1), but it isn't a group. It isn't a group because 0 has no inverse.

[2] Mathematics textbooks typically write this as an equation, instead of using words like "is the same as". We can't use equality in this definition, however, because F 's argument type might not be equality comparable. If F 's argument type is equality comparable, however, then these two expression are expected to be equal: the condition of associativity becomes f(x, f(y, z)) == f(f(x, y), z)

[3] This is implemented as an overloaded function. The function identity_element is defined, in the standard header functional , and the nonstandard backward-compatibility header function.h, for arguments of type plus and multiplies . If you define a new Monoid Operation F (matrix multiplication, for example), you must overload identity_element for arguments of type F . The identity_element function is an SGI extension; it is not part of the C++ standard.

[4] Associativity is not the same as commutativity. That is, the requirement that x * (y * z) == (x * y) * z is completely unrelated to the requirement that x * y == y * x . Monoid operations are required to be associative, but they are not required to be commutative. As an example, square matrices under multiplication form a monoid even though matrix multiplication is not commutative.

See also

Binary Function, plus , multiplies

Random Number Generator

Category: functors

Component type: concept

Description

A Random Number Generator is a function object that can be used to generate a random sequence of integers. That is: if f is a Random Number Generator and N is a positive integer, then f(N) will return an integer less than N and greater than or equal to 0 . If f is called many times with the same value of N , it will yield a sequence of numbers that is uniformly distributed [1] in the range [0, N) . [2]

Refinement of

Unary Function

Associated types
Argument type The type of the Random Number Generator's argument. This must be an integral type.
Result type The type returned when the Random Number Generator is called. It must be the same as the argument type.
Notation

FA type that is a model of Random Number Generator.

IntegerThe argument type of F .

fObject of type F .

NObject of type Integer

Definitions

The domain of a Random Number Generator ( i.e. the set of permissible values for its argument) is the set of numbers that are greater than zero and less than some maximum value.

The range of a Random Number Generator is the set of nonnegative integers that are less than the Random Number Generator's argument.

Valid expressions

None, except for those defined by Unary Function.

Expression semantics
Name Expression Precondition Semantics Postcondition
Function call f(N) N is positive. Returns a pseudo-random number of type Integer . [2] The return value is less than N , and greater than or equal to 0.
Invariants
Uniformity In the limit as f is called many times with the same argument N , every integer in the range [0, N) will appear an equal number of times.
Notes

[1] Uniform distribution means that all of the numbers in the range [0, N) appear with equal frequency. Or, to put it differently, the probability for obtaining any particular value is 1/N .

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Standard Template Library Programmer's Guide»

Представляем Вашему вниманию похожие книги на «Standard Template Library Programmer's Guide» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Standard Template Library Programmer's Guide»

Обсуждение, отзывы о книге «Standard Template Library Programmer's Guide» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x