Created
April 22, 2014 17:21
-
-
Save Enelar/11187440 to your computer and use it in GitHub Desktop.
Filler object with some size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <type_traits> | |
template<int wished_size> | |
struct filler | |
{ | |
static const int word_size = sizeof(int); | |
static const int actual_size_in_words = (wished_size + word_size - 1) / word_size; | |
word_filler<actual_size_in_words> t; | |
}; | |
template<int word_count, typename enabled = void> | |
struct word_filler | |
{ | |
word_filler<word_count / 2> a, b; | |
}; | |
template<int word_count> | |
struct word_filler<word_count, typename std::enable_if<word_count & 1, int>::type> | |
{ | |
word_filler<1> a; | |
word_filler<word_count - 1> b; | |
}; | |
template<> | |
struct word_filler<1, int> | |
{ | |
int t; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment