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


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

Two silly problems

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Two silly problems
Date 2019-12-26 16:47 +0100
Organization A noiseless patient Spider
Message-ID <qu2kmo$6f4$1@dont-email.me> (permalink)

Show all headers | View raw


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)

Back to comp.lang.c++ | Previous | Next — 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