A thread on SO says that extending std
is UB (ok, unless you're the standard writers of course). But from time to time, std
is happily extended. When is it OK to do so?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
You can put template specializations for your custom data types.
As example: your own specialzations of
std::hash
forstd::unordered_map
The only case where it is OK to add a definition into the
std
namespace is specialization of a template that already exists in the namespace and to explicitly instantiate a template. However, only if they depend on a user defined type.[namespace.std] (standard draft):
As an example of standard templates that are explicitly designed to be extended for user defined types:
std::hash
andstd::iterator_traits
.