Namespaces
Variants
Views
Actions

std::experimental::propagate_const

From cppreference.com
< cpp‎ | experimental
Revision as of 00:44, 8 July 2015 by T. Canens (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
 
 
 
template<class T>
class propagate_const;
(library fundamentals TS v2)

std::experimental::propagate_const is a const-propagating wrapper for pointers and pointer-like objects. It treats the wrapped pointer as a pointer to const when accessed through a const access path, hence the name.

The class satisfies the requirements of Template:concept and Template:concept if the underlying pointer-like type satisfies the corresponding concept, but propagate_const is neither Template:concept nor Template:concept.

Type requirements
-
T must be an object pointer type or a pointer-like class type, as specified below. The program is ill-formed if T is an array type, reference type, pointer to function type, pointer to (possibly cv-qualified) void, or if decltype(*std::declval<T&>()) is not an lvalue reference type.

Contents

Requirements on pointer-like class types

If T is a class type, it must satisfy the requirements in this subsection.

Given

  • t, a modifiable lvalue expression of type T
  • ct, a const T& bound to T
  • element_type, an object type

The following expressions must be valid and have their specified effects:

Expression Return type Pre-conditions Operational semantics
t.get() element_type*
ct.get() element_type* or const element_type* t.get() == ct.get()
*t element_type& t.get() |= nullptr *t refers to the same object as *(t.get())
*ct element_type& or const element_type& ct.get() |= nullptr *ct refers to the same object as *(ct.get())
t.operator->() element_type* t.get() |= nullptr t.operator->() == t.get()
ct.operator->() element_type* or const element_type* ct.get() |= nullptr ct.operator->() == ct.get()
(bool)t bool (bool)t is equivalent to t.get() != nullptr
(bool)ct bool (bool)ct is equivalent to ct.get() != nullptr

Further, T and const T shall be contextually convertible to bool.

In addition, if T is implicitly convertible to element_type*, then (element_type*)t shall be equal to t.get(). Similarly, if const T is implicitly convertible to const element_type*, then (const element_type*)ct shall be equal to ct.get().


Member types

Member type Definition
element_type std::remove_reference_t<decltype(*std::declval<T&>())>, the type of the object pointed to by T

Member functions

constructs a new propagate_const
(public member function) [edit]
(destructor)
(implicitly declared)
destructs a propagate_const, destroying the contained pointer
(public member function) [edit]
assigns the propagate_const object
(public member function) [edit]
Modifiers
swaps the wrapped pointer
(public member function) [edit]
Observers
returns a pointer to the object pointed to by the wrapped pointer
(public member function) [edit]
checks if the wrapped pointer is null
(public member function) [edit]
dereferences the wrapped pointer
(public member function) [edit]
implicit conversion function to pointer
(public member function) [edit]

Non-member functions

compares to another propagate_const, another pointer, or with nullptr
(function template) [edit]
specializes the swap algorithm
(function template) [edit]
retrieves a reference to the wrapped pointer-like object
(function template) [edit]

Helper classes

hash support for propagate_const
(class template specialization) [edit]
specializations of the standard comparison function objects for propagate_const
(class template specialization) [edit]

Example