This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Fwd:constexpr w/c++ stdlib features??
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: "Linda A. Walsh" <gcc at tlinx dot org>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Thu, 22 May 2014 13:11:12 +0100
- Subject: Re: Fwd:constexpr w/c++ stdlib features??
- Authentication-results: sourceware.org; auth=none
- References: <537D84FC dot 1040104 at tlinx dot org>
On 21/05/14 22:02 -0700, Linda A. Walsh wrote:
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, "...."};
Why do you need this to be constexpr?
If you really do nee it to be constexpr then you need to use a literal
type that can be initialized at compile-time.
But I get:
g++: COMPILE linux/cpumeter.cc
linux/cpumeter.cc:272:56: error: the type âconst std::vector<const
char*>â of constexpr variable âcpu_states_txtâ is not literal
"HI","SI","STL","GST","NGS", "INT","USED");
^
Obviously since std::vector uses dynamic memory allocation it can't be
a compile-time constant.
Again, why do you need it to be constexpr?
What's wrong with just a const vector?