A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.cplusplus.com/get_pointer_safety below:

function

<memory>

std::get_pointer_safety
pointer_safety get_pointer_safety() noexcept;

Get pointer safety

Returns the pointer safety setting used by the implementation, as a value of type pointer_safety, which can take any of the following values:

value description relaxed The validity of a pointer value does not depend on whether it is a safely-derived pointer value. preferred The validity of a pointer value does not depend on whether it is a safely-derived pointer value.
A leak detector may be running so that the program can avoid spurious leak reports. strict A pointer value that is not a safely-derived pointer value is an invalid pointer value unless the referenced complete object is of dynamic storage duration and has previously been declared reachable.
A garbage collector may be running so that non-traceable object are automatically deleted.


A safely-derived pointer value is a pointer value returned by the default definition of operator new or a value derived from it by well-defined pointer arithmetic, pointer conversions or pointer reinterpretations (reinterpret_cast), including to and from other pointer types or integral types (at least as large as intptr_t), or from sequences of characters with the same size and alignment.

When an implementation uses strict pointer safety, any object dynamically allocated using the default definition of operator new which cannot be traced either by a safely-derived pointer or an equivalent integer representation may be automatically destroyed, invalidating any pointer values that may point to it.

Notice that his does not affect memory allocated dynamically by other means, such as using C-library's malloc or custom redefinitions of operator new.



Parameters none

Return value The pointer safety setting of the compiler.
pointer_safety is an enum class type defined in <memory>.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// get_pointer_safety example
#include <iostream>
#include <memory>

int main() {
  std::cout << "Pointer safety: ";
  switch (std::get_pointer_safety()) {
    case std::pointer_safety::relaxed:   std::cout << "relaxed";   break;
    case std::pointer_safety::preferred: std::cout << "preferred"; break;
    case std::pointer_safety::strict:    std::cout << "strict";    break;
  }
  std::cout << '\n';
  return 0;
}

Possible output:


See also
pointer_safety
Pointer safety enum (enum class)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4