what is a companion types ?

In my book i'm studying the size function of the string class in c++ and my book defines the type returned by this function (size_type) a companion types used to use a library type in a machine indipendent manner , what does it mean ?
I'm a beginerr could you explain me what is a companion types and when it is used ?
std::string::size_type is a member typedef - an alias - for an unsigned integer type that is large enough hold the theoretical maximum size of a string.

std::size_t can store the maximum size of a theoretically possible object of any type (including array). ... std::size_t is commonly used for array indexing and loop counting. Programs that use other types, such as unsigned int, for array indexing may fail on, e.g. 64-bit systems when the index exceeds UINT_MAX or if it relies on 32-bit modular arithmetic.

When indexing C++ containers, such as std::string, std::vector, etc, the appropriate type is the member typedef size_type provided by such containers. It is usually defined as a synonym for std::size_t.
http://en.cppreference.com/w/cpp/types/size_t
Topic archived. No new replies allowed.