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]

Seeming g++-specific "feature deficit"...


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);
}



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