Namespaces
Variants
Views
Actions

std::alignment_of

From cppreference.com
< cpp‎ | types
Revision as of 18:25, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Primary type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++11)
(C++14)
Supported operations
Relationships and property queries
(C++11)
(C++11)
alignment_of
(C++11)
(C++11)
(C++11)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++11)
Type trait constants
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <type_traits>
</td>

<td></td> <td></td> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
template< class T >
struct alignment_of;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Provides the member constant value equal to the alignment requirement of the type T, as if obtained by an alignof expression. If T is an array type, returns the alignment requirements of the element type.

Contents

Inherited from std::integral_constant

Member constants

value
[static]
alignof(typename std::remove_all_extents<T>::type)
(public static member constant)

Member functions

operator std::size_t
converts the object to std::size_t, returns value
(public member function)

Member types

Type Definition
value_type std::size_t
type std::integral_constant<std::size_t, value>

Possible implementation

template< class T >
struct alignment_of : std::integral_constant<
                          std::size_t,
                          alignof(typename std::remove_all_extents<T>::type)
                       > {};

Example

#include <iostream>
#include <type_traits>
 
class A {};
 
int main() 
{
    std::cout << std::alignment_of<A>::value << '\n';
    std::cout << std::alignment_of<int>::value << '\n';
    std::cout << std::alignment_of<double>::value << '\n';
}

Output:

1
4
8

See also

Template:cpp/language/dcl list alignof
defines the type suitable for use as uninitialized storage for types of given size
(class template) [edit]
defines the type suitable for use as uninitialized storage for all given types
(class template) [edit]
POD type with alignment requirement as great as any other scalar type
(typedef) [edit]