Namespaces
Variants
Views
Actions

cpp/named req/CharTraits

From cppreference.com
< cpp‎ | named req
Revision as of 10:21, 5 January 2018 by Ybab321 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:cpp/concept/title Template:cpp/concept/navbar

Template:concept is a traits class that abstracts basic character and string operations for a given character type. Most standard library string and input/output classes require a Template:concept template type parameter alongside a corresponding character template type parameter

Requirements

No operation on Template:concept may throw an exception.

Given

  • CharT, a character type
  • X, a Template:concept type for type CharT
  • c, d, objects of type CharT
  • p, q, objects of type const CharT*
  • s, an object of type CharT*
  • n, i, j, objects of type std::size_t
  • e, f, objects of type X::int_type
  • pos, an object of type X::pos_type
  • state, an object of type X::state_type
  • r, an lvalue of type CharT


expression return type semantics complexity
X::char_type CharT Used to refer to the character type Compile-time
X::int_type An type that can hold all valid values of X::char_type plus X::eof() Compile-time
X::off_type Invokes implementation-defined behaviour if not std::streamoff when X is used as the traits template parameter in input/output classes Compile-time
X::pos_type Invokes implementation-defined behaviour if not std::streampos when X is used as the traits template parameter in input/output classes Compile-time
X::state_type Template:concept, Template:concept, Template:concept Compile-time
X::eq(c,d) bool Returns: whether c is to be treated as equal to d Constant
X::lt(c,d) bool Returns: whether c is to be treated as less than d Constant
X::compare(p,q,n) int Returns:
  • 0 if for each i in [0,n), X​::​eq(p[i], q[i]) is true
  • Else, a negative value if
    • For some j in [0,n), X​::​lt(p[j], q[j]) is true and
    • For each i in [0,j), X​::​eq(p[i], q[i]) is true
  • Else a positive value
Linear
X::length(p) std::size_t Returns: the smallest i such that X​::​eq(p[i], CharT()) is true Linear
X​::​find(p,n,c) const X​::​char_type* Returns:
  • The smallest q in [p,p+n) such that X​::​eq(*q, c) is true
  • Zero otherwise
Linear
X​::​move(s,p,n) X​::​char_type*
  • For each i in [0,n), performs X​::​assign(s[i], p[i])
  • Copies correctly even where the ranges [p,p+n) and [s,s+n) overlap
  • Returns: s
Linear
X​::​copy(s,p,n) X​::​char_type*
  • Requires: p not in [s,s+n)
  • Returns: s
  • For each i in [0,n), performs X​::​assign(s[i], p[i])
Linear
X​::​assign(r,d) (Not used) Assigns r = d Constant
X​::​assign(s,n,c) X​::​char_type*
  • For each i in [0,n), performs X​::​assign(s[i], c).
  • Returns: s
Linear
X​::​not_eof(e) X​::​int_type Returns:
  • e if X​::​eq_int_type(e, X​::​eof()) is false
  • Otherwise a value f such that X​::​eq_int_type(f, X​::​eof()) is false
Constant
X​::​to_char_type(e) X​::​char_type Returns:
  • If for some c, X​::​eq_int_type(e, X​::​to_int_type(c)) is true, c
  • Else some unspecified value
Constant
X​::​to_int_type(c) X​::​int_type Returns: some value e, constrained by the definitions of X::to_char_type and X::eq_int_type Constant
X​::​eq_int_type(e,f) bool
  • For all c and d, X​::​eq(c,d) is equal to X​::​eq_int_type(X​::​to_int_type(c), X​::​to_int_type(d))
  • Returns:
    • Yields X​::​eq(c,d) if for some c and d, e == X::to_int_type(c) and f == X::to_int_type(d)
    • Otherwise, yields true if e and f are both copies of X​::​eof()
    • Otherwise, yields false if one of e and f is a copy of X​::​eof() and the other is not
    • Otherwise the value is unspecified
Constant
X​::​eof() X​::​int_type Returns: a value e such that X​::​eq_int_type(e, X​::​to_int_type(c)) is false for all values c Constant