Fwd:constexpr w/c++ stdlib features??
Jonathan Wakely
jwakely@redhat.com
Thu May 22 12:11:00 GMT 2014
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?
More information about the Libstdc++
mailing list