[Bug c++/63457] New: valarray missing std iterator limit functions

gnu at tlinx dot org gcc-bugzilla@gcc.gnu.org
Sat Oct 4 06:40:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63457

            Bug ID: 63457
           Summary: valarray  missing std iterator limit functions
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnu at tlinx dot org

Running > g++ --version
g++ (SUSE Linux) 4.8.1 20130909 [gcc-4_8-branch revision 202388]
on a recent kernel, I have the following program that comes up with an error:


>  g++ --std=c++11 valA.cc
valA.cc: In function ‘int main(int, char**)’:
valA.cc:34:38: error: ‘class std::valarray<std::basic_string<char> >’ has no
member named ‘begin’
 for (auto &group:groups) sort(group.begin(), group.end());
                                     ^
valA.cc:34:53: error: ‘class std::valarray<std::basic_string<char> >’ has no
member named ‘end’
 for (auto &group:groups) sort(group.begin(), group.end());
                                                    ^
----
What I couldn't figure out was why the valarray had no begin or end members.

It does on the Mac CLANG compiler.

So why not under gnu c++?

It has been noted that if the valarray is changed to a vector, the program
compiles 'fine',
but I wasn't using a vector in my original (no .sum()) so wanted to find out
why it
didn't work w/valarray.    I'm not sure, but if those are missing is this a
larger problem?


------

#include <string>
#include <vector>
#include <valarray>
#include <unordered_map>
#include <algorithm>


using std::vector;
using std::valarray;
using std::string;
using std::unordered_map;
using std::sort;

typedef valarray <string> Options;

vector <Options> groups = {
                         { "red", "green", "orange", "purple", "yellow"},
                         { "apple", "banana", "cherry"},
                         { "butterscotch", "chocolate", "vanilla"},
                         { "rain", "sunny", "hot", "pleasant" }
                       };

// enum {color, fruits, flavors, weather} option_choices;

Options categories = { "color", "fruits", "flavors", "weather" };
unordered_map <string, int> catmap;

int main( int argc, char *argv[] ) {

 int c = 0;
 for (auto &cattxt:categories) catmap[cattxt]=c++;

 for (auto &group:groups) sort(group.begin(), group.end());

 for (auto &cat:catmap) {
   const char *ch="";
   printf("Category: %s\n  ", cat.first.c_str());
   for (auto &opt:groups[cat.second]) {
     printf("%s%s ",ch, opt.c_str());
     ch=",";
   }
   printf("\n");
 }
 exit(0);
}


More information about the Gcc-bugs mailing list