This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: constexpr w/c++ stdlib features??


2014-05-22 7:02 GMT+02:00 Linda A. Walsh <gcc@tlinx.org>:
> I'm trying to convert various 'C'-isms in my code.
>
> I had something that "passed" the "constexpr-test",
> namely, constexpr const char ** cpu_states_txt = {"USR", "Ni", "Sys"...};
>
> This compiled and worked just fine.  But I am trying to change it
> to a vector or valarray:
>
> constexpr const vector<const char *> const cpu_states_txt ={"Usr, "...."};

This cannot reasonably work, because std::vector is no literal type
(it allocates storage dynamically). You may want to consider to use
std::array instead, which is an aggregate container with fixed size.

If the provision of the final size is disturbing for you, you could
simply implement your own make_array function, see the end of

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#851

HTH,

- Daniel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]