M
mrstephengross
I'm trying to find a way to parse apart a string at compile time. I'm
guessing it can't be done. But maybe someone on this group has some
ideas... Here's where I am so far: I know how to templatize a class on
a 'const char *' (see pg. 40 on Vandevoorde's "C++ Templates"). The
code looks like this:
=======================================
extern char const foo [] = "hello";
template<const char * P> class Foo { };
int main() { Foo<foo> f; return 0;
=======================================
So that much works. The next step I want to do is create a class
templatized on a single character, and then instantiate it with the
first character in the foo string. Since foo is const, I figured there
might be a way to make the following work:
=======================================
extern char const foo [] = "hello";
template<char t> class Bar { };
int main() { Bar<foo[0]> b; return 0;
=======================================
Sadly, it does not. The compiler complains that foo[0] is a non-const
argument. Is there some way to get the compiler to understand that the
contents of foo are constant?
Thanks,
--Steve ([email protected])
guessing it can't be done. But maybe someone on this group has some
ideas... Here's where I am so far: I know how to templatize a class on
a 'const char *' (see pg. 40 on Vandevoorde's "C++ Templates"). The
code looks like this:
=======================================
extern char const foo [] = "hello";
template<const char * P> class Foo { };
int main() { Foo<foo> f; return 0;
=======================================
So that much works. The next step I want to do is create a class
templatized on a single character, and then instantiate it with the
first character in the foo string. Since foo is const, I figured there
might be a way to make the following work:
=======================================
extern char const foo [] = "hello";
template<char t> class Bar { };
int main() { Bar<foo[0]> b; return 0;
=======================================
Sadly, it does not. The compiler complains that foo[0] is a non-const
argument. Is there some way to get the compiler to understand that the
contents of foo are constant?
Thanks,
--Steve ([email protected])