Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #70666

Re: Two silly problems

From Bo Persson <bo@bo-persson.se>
Newsgroups comp.lang.c++
Subject Re: Two silly problems
Date 2019-12-26 16:55 +0100
Message-ID <h6k3g7Fp6iaU1@mid.individual.net> (permalink)
References <qu2kmo$6f4$1@dont-email.me>

Show all headers | View raw


On 2019-12-26 at 16:47, Alf P. Steinbach wrote:
> Why, with the below code, do I get this result:
> 
>  > echo no no no not ever | a
> ever 1
> no 1
> not 1
> 
> I had expected a count of three for "no".
> 
> Also, how the feck does the commented line cause a Most Vexing Parse? I 
> was sure that by having a constructor call with `cin` as argument there, 
> i.e. a value argument, there could be no vexing parse. But g++ just 
> doesn't like it and then misleadingly complains about something later in 
> the code, using an avalanche of idiot diagnostics so as to ensure one 
> would waste time on it.
> 
> 
> -------------------------------------------------
> // Read a file of text, determine the n most frequently used words, and 
> print out a sorted
> // list of those words along with their frequencies.
> //
> // 
> https://medium.com/@vgasparyan1995/a-little-bit-of-code-c-20-ranges-c6a6f7eae401 
> 
> 
> // Assuming
> // * ASCII lowercase text
> // * No punctuation.
> 
> #include <iterator>
> #include <iostream>
> #include <string>
> #include <unordered_set>
> 
> template< class Key > using Multiset_ = std::unordered_set<Key>;
> 
> auto main()
>      -> int
> {
>      using std::cin, std::cout, std::endl, std::string;
>      using Iit = std::istream_iterator<string>;
>      const Iit end = Iit();
>      Multiset_<string> words( Iit( cin ), (Iit()) );       // OK
>      //Multiset_<string> words( Iit( cin ), Iit() );       //! Most 
> vexing parse?
>      for( const string& s: words ) {
>          cout << s << ' ' << words.count( s ) << endl;
>      }
> }
> -------------------------------------------------
> 
> 
> - Alf (possibly in superstupido-mode, for various reasons)

Some more coffee needed, possibly?

Multiset_ sounds like a multiset, but it really is not if we read the 
using-line carefully.  :-)

And for the most vexing parse - cin is a value, but it *could* also be 
the name of a parameter for a (hypothetical) words function. So parsing 
a declaration wins!


    Bo Persson


Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-26 16:47 +0100
  Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-26 16:51 +0100
  Re: Two silly problems Bo Persson <bo@bo-persson.se> - 2019-12-26 16:55 +0100
    Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-27 05:07 +0100
      Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-27 16:38 +0000
        Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-27 20:05 +0100
          Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-28 00:42 +0000
            Re: Two silly problems "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-28 07:37 +0100
              Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-28 15:51 +0000
                Re: Two silly problems boltar@nowhere.org - 2019-12-28 16:30 +0000
                Re: Two silly problems Mr Flibble <flibble@i42.removethisbit.co.uk> - 2019-12-28 17:15 +0000

csiph-web