This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Fwd:constexpr w/c++ stdlib features??
- From: "Linda A. Walsh" <gcc at tlinx dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Wed, 21 May 2014 22:02:52 -0700
- Subject: Fwd:constexpr w/c++ stdlib features??
- Authentication-results: sourceware.org; auth=none
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