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

FreeBSD Manual Pages

  
 
  

home | help
std::assume_aligned(3)	      C++ Standard Libary	std::assume_aligned(3)

NAME
       std::assume_aligned - std::assume_aligned

Synopsis
	  Defined in header <memory>
	  template< std::size_t	N, class T >			(since C++20)
	  [[nodiscard]]	constexpr T* assume_aligned( T*	ptr );

	  Informs  the implementation that the object ptr points to is aligned
       to at least N.
	  The implementation may use this information to generate  more	 effi-
       cient code, but it
	  might	 only  make  this assumption if	the object is accessed via the
       return value of
	  assume_aligned.

	  N must be a power of 2. The behavior is undefined if	ptr  does  not
       point to	an object
	  of  type T (ignoring cv-qualification	at every level), or if the ob-
       ject's alignment
	  is not at least N.

Return value
	  ptr.

Exceptions
	  Throws nothing.

Notes
	  To ensure that the program benefits from the	optimizations  enabled
       by
	  assume_aligned,  it is important to access the object	via its	return
       value:

	void f(int* p)
	{
	    int* p1 = std::assume_aligned<256>(p);
	    // Use p1, not p, to ensure	benefit	from the alignment assumption.
	    // However,	the program has	undefined behavior if p	is not aligned
	    // regardless of whether p1	is used.
	}

	  It is	up to the program to ensure that the alignment assumption  ac-
       tually holds. A
	  call	to assume_aligned does not cause the compiler to verify	or en-
       force this.

	     Feature-test macro	    Value    Std	 Feature
	  __cpp_lib_assume_aligned 201811L (C++20) std::assume_aligned

Example
	   This	section	is incomplete
	   Reason: no example

See also
	  alignof operator(C++11)	queries	alignment  requirements	 of  a
       type
	  alignas  specifier(C++11)	  specifies  that  the storage for the
       variable	should be
					aligned	by specific amount
	  aligned_storage		defines	the type suitable for  use  as
       uninitialized
	  (C++11)(deprecated in	C++23)	storage	for types of given size
					(class template)
	  align				aligns a pointer in a buffer
	  (C++11)			(function)
					specifies that the expression will al-
       ways evaluate to
	  [[assume(expression)]](C++23)	true at	a given	point
					(attribute specifier)

Category:
	    * Todo no example

http://cppreference.com		  2024.06.10		std::assume_aligned(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::assume_aligned&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help