Fwd:constexpr w/c++ stdlib features??

Linda A. Walsh gcc@tlinx.org
Thu May 22 05:03:00 GMT 2014


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, "...."};

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");
                                                      ^
In file included from /usr/include/c++/4.8/vector:64:0,
               from ./fieldmetergraph.h:11,
               from linux/cpumeter.h:10,
               from linux/cpumeter.cc:7:
/usr/include/c++/4.8/bits/stl_vector.h:210:11: note: ‘std::vector<const 
char*>’ is not literal because:
   class vector : protected _Vector_base<_Tp, _Alloc>
         ^
/usr/include/c++/4.8/bits/stl_vector.h:210:11: note:   
‘std::vector<const char*>’ has a non-trivial destructor
linux/cpumeter.cc:272:56: error: conversion from ‘const char [5]’ to 
non-scalar type ‘const std::vector<const char*>’ requested
             "HI","SI","STL","GST","NGS", "INT","USED");
---------------------

It seems to be complaining about trying to express this 'constant' in 
terms of
a differnt constant.  Ok...fine... so how would I do it otherwise.

I tried () and {} for init-list, and types vector, valarray and 
array...   Array was
very disappointing in that it had no way to do something that was 
trivial in 'C' --
take it's size from the initializer list.  ARG!  How could someone 
create something
so worthless.  How would you ever get the index and the list 
automatically tied to
coordinate w/each other.  Anyway, vector and valarray both fail 
w/similar messages,

So I hate the idea of just leaving it as 'C', as I've noted the increase in
"power-tools" available to me if I use C++ (like xxx.sum() among 
others).  Is
this something not possible in C++, or is it something g++ doesn't handle?

**Could** it handle it?  I.e. is it within the scope of the std-lib and 
within the
standard (don't know C++ very well -- especially the revised versions( 
last I
used C++ was in V1.0 that had no stdlib...)...

If it is something the lib 'could' (or should) handle, should I submit it
as a RFE or is it a bug?

Thanks much!
Linda








More information about the Libstdc++ mailing list