[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    [Boost-users] Re: "string" values at compile time
From:       David Abrahams <dave () boost-consulting ! com>
Date:       2005-03-31 19:51:10
Message-ID: uu0mrmw5t.fsf () boost-consulting ! com
[Download RAW message or body]

Bruce Trask <Bruce.Trask@prismtech.com> writes:

> Hi,
>
> I want to express a "string" value at compile time.  I am assuming that
> I have to go with mpl::vector<char> and then convert it at runtime to
> its string format.  

I think you mean 

   vector_c< char, ... >

That is basically the only way to get types that are guaranteed to be
different if the contents of the string are different.

> I also have tried using 
>
> struct TestString
> {
>   static const char* getName()
>   {
>     return "TestStringName";
>   }
> };
>
> and then have the user specify TestString and then I write my other code
> to call getName() on the type at runtime.
>
> Are these two choices the best I can hope for with regard to compile-
> time "string" values?


char const test_string[] = "TestStringName";

A pointer or reference to test_string can be used as a template
parameter as long as test_string is declared at namespace scope.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic