pstore2
max.hpp
Go to the documentation of this file.
1 //===- include/pstore/support/max.hpp ---------------------*- mode: C++ -*-===//
2 //* *
3 //* _ __ ___ __ ___ __ *
4 //* | '_ ` _ \ / _` \ \/ / *
5 //* | | | | | | (_| |> < *
6 //* |_| |_| |_|\__,_/_/\_\ *
7 //* *
8 //===----------------------------------------------------------------------===//
9 //
10 // Part of the pstore project, under the Apache License v2.0 with LLVM Exceptions.
11 // See https://github.com/SNSystems/pstore/blob/master/LICENSE.txt for license
12 // information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //===----------------------------------------------------------------------===//
19 #ifndef PSTORE_SUPPORT_MAX_HPP
20 #define PSTORE_SUPPORT_MAX_HPP
21 
22 #include <algorithm>
23 #include <cstddef>
24 #include <cstdint>
25 
26 namespace pstore {
27  namespace details {
28 
29  // size
30  // ~~~~
31  struct size {
32  template <typename T>
33  static constexpr std::size_t value () {
34  return sizeof (T);
35  }
36  };
37 
38  // align
39  // ~~~~~
40  struct align {
41  template <typename T>
42  static constexpr std::size_t value () {
43  return alignof (T);
44  }
45  };
46 
47  } // end namespace details
48 
49  // maxof
50  // ~~~~~
51  template <typename TypeValue, typename... T>
52  struct maxof;
53  template <typename TypeValue>
54  struct maxof<TypeValue> {
55  static constexpr auto value = std::size_t{1};
56  };
57  template <typename TypeValue, typename Head, typename... Tail>
58  struct maxof<TypeValue, Head, Tail...> {
59  static constexpr auto value =
60  std::max (TypeValue::template value<Head> (), maxof<TypeValue, Tail...>::value);
61  };
62 
63  // characteristics
64  // ~~~~~~~~~~~~~~~
66  template <typename... T>
67  struct characteristics {
68  static constexpr std::size_t size = maxof<details::size, T...>::value;
69  static constexpr std::size_t align = maxof<details::align, T...>::value;
70  };
71 
72 } // end namespace pstore
73 
75  sizeof (std::uint_least8_t),
76  "max(sizeof(1)) != sizeof(1)");
77 static_assert (
79  sizeof (std::uint_least16_t),
80  "max(sizeof(1),sizeof(2) != 2");
81 
82 #endif // PSTORE_SUPPORT_MAX_HPP
Given a list of types, find the size of the largest and the alignment of the most aligned...
Definition: max.hpp:67
Definition: print.cpp:18
Definition: nonpod2.cpp:40
Definition: max.hpp:52
Definition: max.hpp:31
Definition: max.hpp:40