Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
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  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  de-
       cltype(*std::declval<T&>())
	  is not an lvalue reference type.

	 Requirements on pointer-like class types

	  If T is a class type,	it must	satisfy	the requirements in this  sub-
       section.

	  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 ef-
       fects:

	    Expression		Return type	    Pre-conditions	Opera-
       tional semantics
	  t.get()	  element_type*
	  ct.get()	  element_type*	or  const		       t.get()
       == ct.get()
			  element_type*
	  *t		  element_type&		 t.get() != nullptr  *t	refers
       to the same
								     object as
       *(t.get())
	  *ct		   element_type&  or  const  ct.get()  !=  nullptr *ct
       refers to the same
			  element_type&				     object as
       *(ct.get())
	  t.operator->()  element_type*		 t.get() != nullptr   t.opera-
       tor->() == t.get()
	  ct.operator->() element_type*	or const ct.get() != nullptr ct.opera-
       tor->() ==
			  element_type*				     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  con-
       vertible	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
	  constructor		       constructs a new	propagate_const
				       (public member function)
	  destructor		       destructs an propagate_const,  destroy-
       ing 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==
	  operator!=						      compares
       to another
	  operator<							propa-
       gate_const, another
	  operator<=						      pointer,
       or with nullptr
	  operator>							(func-
       tion template)
	  operator>=
								      special-
       izes the	swap
	  std::experimental::swap(std::experimental::propagate_const)	 algo-
       rithm
								      (func-
       tion template)
								      Re-
       trieves a reference to
	  get_underlying						   the
       wrapped pointer-like
								      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 <iostream>
	#include <memory>
	#include <experimental/propagate_const>

	struct X
	{
	    void g() const { std::cout << "g (const)\n"; }
	    void g() { std::cout << "g (non-const)\n"; }
	};

	struct Y
	{
	    Y()	: m_ptrX(std::make_unique<X>())	{ }

	    void f() const
	    {
		std::cout << "f	(const)\n";
		m_ptrX->g();
	    }

	    void f()
	    {
		std::cout << "f	(non-const)\n";
		m_ptrX->g();
	    }

	    std::experimental::propagate_const<std::unique_ptr<X>> m_ptrX;
	};

	int main()
	{
	    Y y;
	    y.f();

	    const Y cy;
	    cy.f();
	}

Output:
	f (non-const)
	g (non-const)
	f (const)
	g (const)

http://cppreference.com		  2022.07.31	  std::experi...agate_const(3)

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.0>

home | help