const native arrays at compile time

Hello, I have a number of questions, some of which are boost specific. 1. const std::string cols[] = { "col1", "col2", "col3" }; Is the const native array cols completely a compile-time construct or are std::string objects constructed at runtime? I would guess the latter? 2. const char const* cols[] = { "col1", "col2", "col3" }; This on the other hand would be pure compile time? 3. struct S1 { const char const* cols[] = { "col1", "col2", "col3" }; }; struct S2 { const char const* cols[] = { "colx", "coly", "coly" }; }; template <typename T> /// T is either S1 or S2 struct S { const char const* col1s[] = { "othercol", /// elements of T::cols }; }; Is there a way to build col1s at compile time? MM

On Thu, Jul 12, 2012 at 3:07 AM, Hicham Mouline
I have a number of questions, some of which are boost specific.
Hmm, haven't yet spotted the Boost questions.
1. const std::string cols[] = { "col1", "col2", "col3" }; Is the const native array cols completely a compile-time construct or are std::string objects constructed at runtime? I would guess the latter?
It would surprise me greatly if any compiler would run library runtime code at compile time in order to construct static objects.
2. const char const* cols[] = { "col1", "col2", "col3" }; This on the other hand would be pure compile time?
Yes, should work even in classic C.
3. struct S1 { const char const* cols[] = { "col1", "col2", "col3" }; }; struct S2 { const char const* cols[] = { "colx", "coly", "coly" }; };
template <typename T> /// T is either S1 or S2 struct S {
const char const* col1s[] = { "othercol", /// elements of T::cols }; };
Is there a way to build col1s at compile time?
I confess I'm not sure what you're trying to accomplish here. Wouldn't it suffice for the methods of S to directly reference T::cols ?

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Nat Linden Sent: 12 July 2012 14:05 To: boost-users@lists.boost.org Subject: Re: [Boost-users] const native arrays at compile time
On Thu, Jul 12, 2012 at 3:07 AM, Hicham Mouline
wrote: I have a number of questions, some of which are boost specific.
Hmm, haven't yet spotted the Boost questions.
1. const std::string cols[] = { "col1", "col2", "col3" }; Is the const native array cols completely a compile-time construct or are std::string objects constructed at runtime? I would guess the latter?
It would surprise me greatly if any compiler would run library runtime code at compile time in order to construct static objects.
2. const char const* cols[] = { "col1", "col2", "col3" }; This on the other hand would be pure compile time?
Yes, should work even in classic C.
3. struct S1 { const char const* cols[] = { "col1", "col2", "col3" }; }; struct S2 { const char const* cols[] = { "colx", "coly", "coly" }; };
template <typename T> /// T is either S1 or S2 struct S {
const char const* col1s[] = { "othercol", /// elements of T::cols }; };
Is there a way to build col1s at compile time?
I confess I'm not sure what you're trying to accomplish here. Wouldn't it suffice for the methods of S to directly reference T::cols ? _______________________________________________
Because col1s is then passed elsewhere, and it would be nice if it didn't need to be built at runtime MM,
participants (3)
-
Hicham Mouline
-
MM
-
Nat Linden