Skip to content

Instantly share code, notes, and snippets.

@Enelar
Created April 22, 2014 17:21
Show Gist options
  • Save Enelar/11187440 to your computer and use it in GitHub Desktop.
Save Enelar/11187440 to your computer and use it in GitHub Desktop.
Filler object with some size
#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