Skip to content

Instantly share code, notes, and snippets.

@ben0x539
Created September 23, 2011 15:11
Show Gist options
  • Save ben0x539/1237607 to your computer and use it in GitHub Desktop.
Save ben0x539/1237607 to your computer and use it in GitHub Desktop.
#include <iostream>
enum values {
V0, V1, V2, V3, V4, V5
};
template<typename T>
struct named_array {
const char* name;
std::size_t size;
T* v;
template<typename... Args>
named_array(const char* name, Args... values)
: name(name), size(sizeof...(values)),
v(new T[sizeof...(values)] { values... })
{}
~named_array() {
delete[] v;
}
};
int main() {
named_array<values> ary("derp", V1, V3, V4);
std::cout << ary.name;
for (std::size_t i = 0; i < ary.size; ++i)
std::cout << ", " << (int) ary.v[i];
std::cout << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment