Remove CDS_RVALUE_SUPPORT, CDS_MOVE_SEMANTICS_SUPPORT macros and emulating code
[libcds.git] / cds / details / type_padding.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_DETAILS_TYPE_PADDING_H
4 #define __CDS_DETAILS_TYPE_PADDING_H
5
6 namespace cds { namespace details {
7
8     //@cond none
9     template <typename T, int Align, int Modulo>
10     struct type_padding_helper: public T
11     {
12         enum {
13             value = Modulo
14         };
15         char _[Align - Modulo]   ;   // padding
16
17         type_padding_helper() CDS_NOEXCEPT_( noexcept( T() ))
18         {}
19     };
20     template <typename T, int Align>
21     struct type_padding_helper<T, Align, 0>: public T
22     {
23         enum {
24             value = 0
25         };
26
27         type_padding_helper() CDS_NOEXCEPT_( noexcept( T()) )
28         {}
29     };
30     //@endcond
31
32     /// Automatic alignment type \p T to \p AlignFactor
33     /**
34         The class adds appropriate bytes to type T that the following condition is true:
35         \code
36         sizeof( type_padding<T,AlignFactor>::type ) % AlignFactor == 0
37         \endcode
38         It is guaranteed that count of padding bytes no more than AlignFactor - 1.
39
40         \b Applicability: type \p T must not have constructors another that default ctor.
41         For example, \p T may be any POD type.
42     */
43     template <typename T, int AlignFactor>
44     class type_padding {
45     public:
46         /// Result type
47         typedef type_padding_helper<T, AlignFactor, sizeof(T) % AlignFactor>    type;
48
49         /// Padding constant
50         enum {
51             value = type::value
52         };
53     };
54
55 }}   // namespace cds::details
56 #endif // #ifndef __CDS_DETAILS_TYPE_PADDING_H