Created
September 23, 2011 15:11
-
-
Save ben0x539/1237607 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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