FreeBSD Manual Pages
std::experi...agate_const(3) C++ Standard Libary std::experi...agate_const(3) NAME std::experimental::propagate_const - std::experimental::propagate_const Synopsis Defined in header <experimental/propagate_const> template< class T > (library fundamen- tals TS v2) class propagate_const; 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 MoveConstructible and Move- Assignable if the underlying pointer-like type satisfies the corresponding require- ment, but propagate_const is neither CopyConstructible nor CopyAssignable. Type requirements - T must be cv-unqualified pointer-to-object type or a cv-unqualified pointer-like class type, as specified below. 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 constructor constructs a new propagate_const (public member function) destructor destructs a propagate_const, destroying the contained (implicitly declared) pointer (public member function) operator= assigns the propagate_const object (public member function) swap swaps the wrapped pointer (public member function) Observers returns a pointer to the object pointed to by the get wrapped pointer (public member function) operator bool checks if the wrapped pointer is null (public member function) operator* dereferences the wrapped pointer operator-> (public member function) operator element_type* implicit conversion function to pointer operator const element_type* (public member function) Non-member functions operator== compares to another operator!= propa- gate_const, another operator< pointer, or with nullptr operator<= (func- tion template) operator> operator>= special- izes the swap std::experimental::swap(std::experimental::propagate_const) algo- rithm (func- tion template) re- trieves a reference to the wrapped pointer-like get_underlying object (func- tion template) Helper classes hash support for std::hash<std::experimental::propagate_const> propa- gate_const (class tem- plate specializa- tion) std::equal_to<std::experimental::propagate_const> specializa- tions of the std::not_equal_to<std::experimental::propagate_const> standard com- parison function std::less<std::experimental::propagate_const> objects for propagate_const std::greater<std::experimental::propagate_const> (class tem- plate std::less_equal<std::experimental::propagate_const> specializa- tion) std::greater_equal<std::experimental::propagate_const> Example // Run this code #include <experimental/propagate_const> #include <iostream> #include <memory> struct X { void g() const { std::cout << "X::g (const)\n"; } void g() { std::cout << "X::g (non-const)\n"; } }; struct Y { Y() : m_propConstX(std::make_unique<X>()), m_autoP- trX(std::make_unique<X>()) {} void f() const { std::cout << "Y::f (const)\n"; m_propConstX->g(); m_autoPtrX->g(); } void f() { std::cout << "Y::f (non-const)\n"; m_propConstX->g(); m_autoPtrX->g(); } std::experimental::propagate_const<std::unique_ptr<X>> m_propCon- stX; std::unique_ptr<X> m_autoPtrX; }; int main() { Y y; y.f(); const Y cy; cy.f(); } Output: Y::f (non-const) X::g (non-const) X::g (non-const) Y::f (const) X::g (const) X::g (non-const) Defect reports The following behavior-changing defect reports were applied retroac- tively to previously published C++ standards. DR Applied to Behavior as published Correct behavior LWG 3136 LFTSv2 meaningless T like int* const, void*, or const disallowed PtrLike were allowed http://cppreference.com 2024.06.10 std::experi...agate_const(3)
NAME | Synopsis | Type requirements | Member types | Member functions | Observers | Non-member functions | Helper classes | Example | Output:
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::experimental::propagate_const&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>
