cpp/language/extending std

Adding declarations to
It is undefined behavior to add declarations or definitions to namespace or to any namespace nested within, with a few exceptions noted below.

Class templates
It is allowed to add template specializations for any standard library class template to the namespace only if the declaration depends on at least one program-defined type and the specialization satisfies all requirements for the original template, except where such specializations are prohibited.


 * Specializing the template std for any type other than float, double, and long double is unspecified.


 * Specializations of std must define all members declared in the primary template, in such a way that they are usable as.

It is undefined behavior to declare a full or partial specialization of any member class template of a standard library class or class template.

Function templates and member functions of templates
It is undefined behavior to declare a full specialization of any member function of a standard library class template:

It is undefined behavior to declare a full specialization of any member function template of a standard library class or class template:

Explicit instantiation of templates
It is allowed to explicitly instantiate a template defined in the standard library only if the declaration depends on the name of at least one program-defined type and the instantiation meets the standard library requirements for the original template.

Program-defined types
Program-defined specializations are explicit template specializations or partial specializations that are not part of the C++ standard library and not defined by the implementation.

Program-defined types are non-closure or  that are not part of the C++ standard library and not defined by the implementation, or instantiation of program-defined specializations.

Other restrictions
The namespace may not be declared as an.

{{rrev|since=c++20|

Addressing restriction
The behavior of a C++ program is unspecified (possibly ill-formed) if it explicitly or implicitly attempts to form a pointer, reference (for free functions and static member functions) or pointer-to-member (for non-static member functions) to a standard library function or an instantiation of a standard library function template, unless it is designated an addressable function (see below).

Following code was well-defined in C++17, but leads to unspecified behaviors and possibly fails to compile since C++20:

Designated addressable functions

 * I/O manipulators:
 * manipulators:
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * std
 * manipulators:
 * std
 * std
 * std
 * manipulators:
 * std
 * std
 * std
 * manipulators:
 * std
 * std
 * std
 * std
 * manipulators:
 * std
 * manipulators:
 * std
 * std
 * std

}}