This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: constexpr w/c++ stdlib features??
- From: Daniel Krügler <daniel dot kruegler at gmail dot com>
- To: "Linda A. Walsh" <gcc at tlinx dot org>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 22 May 2014 08:04:29 +0200
- Subject: Re: constexpr w/c++ stdlib features??
- Authentication-results: sourceware.org; auth=none
- References: <537D84FC dot 1040104 at tlinx dot org>
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