-
Notifications
You must be signed in to change notification settings - Fork 2
/
CacheAligned.hpp
37 lines (32 loc) · 1.02 KB
/
CacheAligned.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef CACHEALIGNED_HPP_INCLUDED
#define CACHEALIGNED_HPP_INCLUDED
#include <cstddef>
#include <initializer_list>
#include <type_traits>
#include "Aligned.hpp"
#include "CacheAlignedBase.hpp"
#include "InitializerListLongerThanSizeException.hpp"
template<typename T>
class CacheAligned : public Aligned<T>, CacheAlignedBase<T> {
public:
template<typename... Args>
CacheAligned(Args &&... args) : Aligned(cacheLineSize(), std::forward<Args>(args)...) {}
};
template<typename T>
class CacheAligned<T[]> : public Aligned<T[]>, CacheAlignedBase<T> {
public:
CacheAligned(std::size_t size) : Aligned(cacheLineSize(), size) {}
CacheAligned(std::size_t size, std::initializer_list<T> const & list)
: CacheAligned(size)
{
if (size < list.size())
throw InitializerListLongerThanSizeException();
int i = 0;
for (auto it = list.begin(); it != list.end(); ++it)
this->element(i++) = *it;
}
CacheAligned(std::initializer_list<T> const & list)
: CacheAligned(list.size(), list)
{}
};
#endif