encyclopegia.org

Utility (C++)

is a header file in the C++ Standard Library.[src] This file has two key components: * , a namespace containing set of templates which define default behavior for the relational operators , , , and between objects of the same type, based on user-defined operators and .[src] * , a container template which holds two member objects ( and ) of arbitrary type(s).[src] Additionally, the header defines default relational operators for s which have both types in common.[src]

is a header file in the C++ Standard Library.[src] This file has two key components: , a namespace containing set of templates which define default behavior for the relational operators , , , and between objects of the same type, based on user-defined operators and .[src] , a container template which holds two member objects ( and ) of arbitrary type(s).[src] Additionally, the header defines default relational operators for s which have both types in common.[src] == == GCC's implementation declares the namespace in a manner similar to the following: namespace std::rel_ops { template inline bool operator!=(const T& x, const T& y) { return !(x == y); } template inline bool operator>(const T& x, const T& y) { return y inline bool operator inline bool operator>=(const T& x, const T& y) { return !(x Consider the following declaration of , which defines equality and less-than operators for comparison against other objects of the same type: import std; using namespace std::rel_ops; class BuildingLocation { unsigned int building; unsigned int room; public: bool operator==(const BuildingLocation& other) const { return (building == other.building) && (room == other.room); } bool operator a2; // error: no match for ‘operator >’ in ‘a1 > a2’ bool less_equal = a1 = a2; // error: no match for ‘operator>=’ in ‘a1 >= a2’ } By invoking the templates, one can assign a default meaning to the remaining relational operators.[src] However, if a similar type-specific (i.e.[src] non-template) operator exists in the current scope, even outside the class definition, the compiler will prefer it instead.[src] // (continued from above) // below operator supersedes rel_ops bool operator>=(const BuildingLocation& a1, const BuildingLocation& a2) { do_something_else(); // perform some distinguishing side-effect return !(a1 a2; // uses (a2 = a2; // uses global operator >= defined above } One could of course declare the following in tandem with , allowing the derivation of all relational operators from : template inline bool operator==(const T& x, const T& y) { return !(x == == is a struct that encapsulates two objects of two types.[src] An object declared, for example, as will contain two members, and , plus three constructor functions.[src] The first (default) constructor initializes both members with the default values and , whereas the second one accepts one parameter of each type.[src] The third is a template copy-constructor which will accept any , provided the types and are capable of implicit conversion to and respectively.[src] The implementation of std::pair looks roughly similar to the following: namespace std { template struct pair { using first_type = T1; using second_type = T2; T1 first; T2 second; pair(): first(), second() {} pair(const T1& a, const T2& b): first(a), second(b) {} template pair(const pair & p): first(p.first), second(p.second) {} }; } Additionally this header defines all six relational operators for instances with both types in common.[src] These define a strict weak ordering for objects of type , based on the elements and then upon the elements only when the ones are equal.[src] namespace std { template inline bool operator==(const pair & x, const pair & y) { return x.first == y.first && x.second == y.second; } template inline bool operator & x, const pair & y) { return x.first inline bool operator!=(const pair & x, const pair & y) { return !(x == y); } template inline bool operator>(const pair & x, const pair & y) { return y inline bool operator & x, const pair & y) { return !(y inline bool operator>=(const pair & x, const pair & y) { return !(x Additionally the header contains a template-function which deduces its return type based on parameters: namespace std { // continued from above template inline pair make_pair(T1 x, T2 y) { return pair (x,y); } } ==See also== Relational operator ==References== ==External links== C++ reference for general utilities library[src]

18 sentences · 18 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Utility (C++)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/utility-c. Accessed 25 November 2026.

Chicago

"Utility (C++)." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/utility-c.

APA

encyclopegia.org. (2026). Utility (C++). Retrieved November 25, 2026, from https://encyclopegia.org/wiki/utility-c

Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

utility knife

stub · references available

utility model

stub · references available

Utility Muffin Research Kitchen

stub · references available

OpenGL Utility Library

stub · references available

multi-utility

stub · references available

Disk Utility

stub · references available

Energy and Utility Skills

stub · references available

Grant County Public Utility District

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1339984161 · 0.5 · snapshot enwiki-001339984161

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.