Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::is_sufficiently_aligned

      From cppreference.com
      <cpp‎ |memory
       
       
      Memory management library
      (exposition only*)
      Allocators
      Uninitialized memory algorithms
      Constrained uninitialized memory algorithms
      Memory resources
      Uninitialized storage(until C++20)
      (until C++20*)
      (until C++20*)
      Garbage collector support(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
       
      Defined in header<memory>
      template<std::size_t N,class T>
      bool is_sufficiently_aligned( T* ptr);
      (since C++26)

      Checks whether the pointerptr points to an object whose alignment has a value of at leastN.

      The behavior is undefined ifptr does not point to an object of typeT (ignoring cv-qualification at every level).

      Contents

      [edit]Return value

      true ifptr points to an object that has alignment at leastN; otherwisefalse.

      [edit]Exceptions

      Throws nothing.

      [edit]Notes

      std::is_sufficiently_aligned can be used as a precondition tostd::assume_aligned.

      Feature-test macroValueStdFeature
      __cpp_lib_is_sufficiently_aligned202411L(C++26)std::is_sufficiently_aligned

      [edit]Possible implementation

      template<std::size_t N,class T>bool is_sufficiently_aligned(T* ptr){returnstd::bit_cast<std::uintptr_t>(ptr)% N==0;}

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      alignof(C++11) queries alignment requirements of a type
      (operator)[edit]
      alignas(C++11) specifies that the storage for the variable should be aligned by specific amount
      (specifier)[edit]
      (since C++11)(deprecated in C++23)
      defines the type suitable for use as uninitialized storage for types of given size
      (class template)[edit]
      (C++11)
      aligns a pointer in a buffer
      (function)[edit]
      a type for aligned access to elements ofmdspan
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/is_sufficiently_aligned&oldid=178887"

      [8]ページ先頭

      ©2009-2025 Movatter.jp