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: Fwd:constexpr w/c++ stdlib features??


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?


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