I'm playing around with TMP in GCC 4.3.2's half-implementation of C++11, and I was wondering if there was a way to somehow do the following:
template <char x, char... c>
struct mystruct {
...
};
int main () {
mystruct<"asdf">::go();
}
It obviously won't let me do it just like that, and I thought I'd get lucky by using user-defined literals to transform the "asdf" string during compile-time, but GCC 4.3 doesn't support user-defined literals...
Any suggestions? I'd prefer to not do 'a','s','d','f', since this severely hampers my plans for this project.
I solved a problem similar to this. We needed a different type for each name
template< const char* the_name >
class A
{
public:
const char* name( void )
{
return the_name;
}
};
extern const char g_unique_name[]; // defined elsewhere
typedef A<g_unique_name> A_unique;
This will gave you compile time access to the name, and unique instantiation. It however will not let you access the individual characters at run time.
If you want individual character access the only way to achieve it is with a user defined literal. C++0x will be extended to allow the syntax in your main function above but it will still bind the template to a character pointer not to a compile time array of characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With