MCPcopy Create free account
hub / github.com/alibaba/yalantinglibs / alignment_impl

Function alignment_impl

include/ylt/struct_pack/alignment.hpp:91–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90template <typename T>
91constexpr std::size_t alignment_impl() {
92 if constexpr (struct_pack::detail::is_compatible_v<T>) {
93 return 0;
94 }
95 else if constexpr (struct_pack::alignment_v<T> == 0 &&
96 struct_pack::pack_alignment_v<T> == 0) {
97 return default_alignment_v<T>;
98 }
99 else if constexpr (struct_pack::alignment_v<T> != 0) {
100 if constexpr (is_trivial_serializable<T>::value) {
101 static_assert(default_alignment_v<T> == alignment_v<T>);
102 }
103 constexpr auto ret = struct_pack::alignment_v<T>;
104 static_assert(
105 [](std::size_t align) constexpr {
106 while (align % 2 == 0) {
107 align /= 2;
108 }
109 return align == 1;
110 }(ret),
111 "alignment should be power of 2");
112 return ret;
113 }
114 else {
115 if constexpr (is_trivial_serializable<T>::value) {
116 return default_alignment_v<T>;
117 }
118 else {
119 return pack_alignment_v<T>;
120 }
121 }
122}
123template <typename P, typename T, std::size_t I>
124struct calculate_trival_obj_size {
125 constexpr void operator()(std::size_t &total);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected