constexpr w/c++ stdlib features??
Daniel Krügler
daniel.kruegler@gmail.com
Thu May 22 06:04:00 GMT 2014
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
More information about the Libstdc++
mailing list