A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/type_traits/alignment_of/ below:

class template

<type_traits>

std::alignment_of
template <class T> struct alignment_of;

Alignment of


Trait class to obtain the alignment requirement of type T.

If T is a reference type, the alignment obtained is the one required by the referenced type.

If T is an array type, the alignment obtained is the one required by the element type.

The class behaves as if defined as:


1
template<class T> struct alignment_of : integral_constant <size_t,alignof(T)> {};

Template parameters
T
A complete object type, or an array thereof, or a reference to a complete object type.

Member types Inherited from integral_constant:

Member constants Inherited from integral_constant:
member constant definition value alignof(T)
Member functions Inherited from integral_constant:
operator size_t
Returns value (public member function)

Example
1
2
3
4
5
6
7
8
9
10
11
12
// alignment_of example
#include <iostream>
#include <type_traits>

int main() {
  std::cout << "alignment_of:" << std::endl;
  std::cout << "char: " << std::alignment_of<char>::value << std::endl;
  std::cout << "int: " << std::alignment_of<int>::value << std::endl;
  std::cout << "int[20]: " << std::alignment_of<int[20]>::value << std::endl;
  std::cout << "long long int: " << std::alignment_of<long long int>::value << std::endl;
  return 0;
}

Possible output:
alignment_of
char: 1
int: 4
int[20]: 4
long long int: 8


See also
rank
Array rank (class template)
extent
Array dimension extent (class template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4