分享方式:


aligned_storage 類別

建立適當對齊的類型。

語法

template <std::size_t Len, std::size_t Align>
struct aligned_storage;

template <std::size_t Len, std::size_t Align = alignment_of<max_align_t>::value>
using aligned_storage_t = typename aligned_storage<Len, Align>::type;

參數

Len
物件大小。

契合
物件對齊。

備註

範本成員 typedef type 是具有對齊方式 大小 Len 之 POD 類型的同義字。 對齊 必須等於 alignment_of<T>::value 某些類型 T ,或預設對齊方式。

範例

#include <type_traits>
#include <iostream>

typedef std::aligned_storage<sizeof (int),
    std::alignment_of<double>::value>::type New_type;
int main()
    {
    std::cout << "alignment_of<int> == "
        << std::alignment_of<int>::value << std::endl;
    std::cout << "aligned to double == "
        << std::alignment_of<New_type>::value << std::endl;

    return (0);
    }
alignment_of<int> == 4
aligned to double == 8

需求

標頭: < type_traits>

命名空間:std

另請參閱

<type_traits>
alignment_of 類別