The first dimension of zero is acceptable, and the allocation function is called. The behavior is undefined if the value in the first dimension (converted to integral or enumeration type if needed) is negative. The following behavior-changing defect reports were applied bat token exchange data retroactively to previously published C++ standards. These operators are sometimes implemented as friend functions.
- The first dimension of zero is acceptable, and the allocation function is called.
- For a non-placement allocation function, the normal deallocation function lookup is used to find the matching deallocation function (see delete-expression).
- If the implementation is allowed to introduce a temporary object or make a copy of any argument as part of the call to the allocation function, it is unspecified whether the same object is used in the call to both the allocation and deallocation functions.
- POSIX specifies many additional details for the behavior of this function.
delete expression
For a non-placement allocation function, the normal deallocation function lookup is used to find the matching deallocation function (see delete-expression). The new expression attempts to allocate storage and then attempts to construct and initialize either a single unnamed object, or an unnamed array of objects in the allocated storage. The new expression returns a prvalue pointer to the constructed object or, if an array of objects was constructed, a pointer to the initial element of the array.
Function call operator
Overloads of operator new and operator new with additional user-defined parameters (“placement forms”), may also be defined as class members (19-22)). When the placement new expression with the matching signature looks for the corresponding allocation function to call, it begins at class scope before examining the global scope, and if the class-specific placement new is provided, it is called. The new expression looks for appropriate allocation function’s name firstly in the class scope, and after that in the global scope. Note, that as per name lookup rules, any allocation functions declared in class scope hides all global allocation functions for the new expressions that attempt to allocate objects of this class. At the point in the code the operator() is called, the type must be complete.
If the shared pointer p owns a deleter of type cv-unqualified Deleter (e.g. if it was created with one of the constructors that take a deleter as a parameter), then returns a pointer to the deleter. Performs contextual conversion to bool, user-defined classes that are intended to be used in boolean contexts could provide only operator bool and need not overload operator!. Creates and initializes objects with dynamic storage duration, that is, objects whose lifetime is not necessarily limited by the scope in which they were created.
- This form automatically provides strong exception guarantee, but prohibits resource reuse.
- Removing is done by shifting the elements in the range in such a way that the elements that are not to be removed appear in the beginning of the range.
- Creates and initializes objects with dynamic storage duration, that is, objects whose lifetime is not necessarily limited by the scope in which they were created.
- Unless otherwise specified, the remaining description in this page does not apply to these functions.
Dynamic arrays
A call to remove is typically followed by a call to a container’s erase member function to actually remove elements from the container. These two invocations together constitute a so-called erase-remove idiom. If the value type of ForwardIt is not CopyAssignable, the behavior is undefined.
Class-specific overloads
Itanium C++ ABI requires that the array allocation overhead is zero if the element type of the created array is trivially destructible. If new-initializer is a braced-enclosed initializer list, and the first dimension is potentially evaluated and not a core constant expression, the semantic constraints of copy-initializing a hypothetical element of the array from an empty initializer list are checked. The returned pointer is valid at least as long as there remains at least one shared_ptr instance that owns it. A pointer to void cannot be deleted because it is not a pointer to an object type. Destroys object(s) previously allocated by the new-expression and releases obtained memory area.
Deallocates storage previously allocated by a matching operator new or operator new. These deallocation functions are called by delete and delete expressions and by placement new expressions to deallocate memory after destructing (or failing to construct) objects with dynamic storage duration. Regardless of which deallocation function would be executed at run time, the statically visible version of operator delete must be accessible in order to compile. In other cases, when deleting an array through a pointer to base, or when deleting through pointer to base with non-virtual destructor, the behavior is undefined. The delete expression looks for appropriate deallocation function’s name starting from the class scope (array form looks in the scope of the array element class) and proceeds to the global scope if no members are found as usual. Note, that as per name lookup rules, any deallocation functions declared in class scope hides all global deallocation functions.
This form automatically provides strong exception guarantee, but prohibits resource reuse. Removing is done by shifting the elements in the range in such a way that the elements that are not to be removed appear in the beginning of the range. The object created by a new expression is initialized according to the following rules.
Rarely overloaded operators
The behaviors of non-punctuation operators are described in their own respective pages. Unless otherwise specified, the remaining description in this page does not apply to these functions. Customizes the C++ operators for operands of user-defined types. If the file is currently open by any process, the behavior of this function is implementation-defined. POSIX systems unlink the file name (directory entry), but the filesystem space used by the file is not reclaimed while it is open in any process and while other hard links to the file exist.
In some implementations a static_assert is used to make sure this is the case. Overloads of operator new and operator new with additional user-defined parameters (“placement forms”, versions (11-14)) may be declared at global scope as usual, and are called by the matching placement forms of new expressions. If ptr is a null pointer value, no destructors are called, andthe deallocation function may or may not be called (it’s unspecified), but the default deallocation functions are guaranteed to do nothing when passed a null pointer. If the object being deleted has incomplete class type at the point of deletion, and the complete class has a non-trivial destructor or a deallocation function, the behavior is undefined(until C++26)the program is ill-formed(since C++26). The destructor must be accessible from the point where the delete-expression appears.
operator new, operator new
All deallocation functions are noexcept(true) unless specified otherwise in the declaration. However, when these operators appear in expressions, they still require an object of class type. The new expression allocates storage by calling the appropriate allocation function. If type is a non-array type, the name of the function is operator new. If type is an array type, the name of the function is operator new.
The selected deallocation function must be accessible from the point where the delete-expression appears, unless the deallocation function is selected at the point of definition of the dynamic type’s virtual destructor. For a placement allocation function, the matching deallocation function must have the same number of parameter, and each parameter type except the first is identical to the corresponding parameter type of the allocation function (after parameter transformations). Attempts to allocate requested number of bytes, and the allocation request can fail (even if the requested number of bytes is zero). These allocation functions are called by new expressions to allocate memory in which new object would then be initialized. If the implementation is allowed to introduce a temporary object or make a copy of any argument as part of the call to the allocation function, it is unspecified whether the same object is used in the call to both the allocation and deallocation functions.
Calls to these functions that allocate or deallocate a particular unit of storage occur in a single total order, and each such deallocation call happens-before the next allocation (if any) in this order. Overloaded operators that are member functions can be declared static. On freestanding implementations, it is implementation-defined whether the default versions of (1-8) satisfy the behaviors required above. Freestanding implementations are recommended that if any of these default versions meet the requirements of a hosted implementation, they all should.
