Boost logo

Boost :

Subject: Re: [boost] [type_erasure] Review started (July 18-27, 2012)
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2012-08-06 05:55:35


> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Steven
> Watanabe
> Sent: Friday, August 03, 2012 7:40 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] [type_erasure] Review started (July 18-27, 2012)
>
> AMDG

Further to my enthusiastic welcome to print sequence example, I have extended this to other types,
but come unstuck for std::map :-(

I've created a map

    std::map<int, double> my_map;
    my_map.insert(std::make_pair(1, 9.9));
    my_map.insert(std::make_pair(2, 8.8));

and made sure I can output the values using a forward iterator

    for (std::map<int, double>::iterator it = my_map.begin(); it != my_map.end(); ++it)
    {
      std::cout << *it << std::endl;
    }

with an operator<< for pair (untidily in global namespace for the purpose of this example).

template <typename K, typename T>
std::ostream& operator<< (std::ostream& os, std::pair<K, T>& p)
{ /*! Output a pair of values.
      \details For example: "1.23 , 3.45".
    */
   os << p.first << ", " << p.second;
   return os;
}

And I can echo the input as expected

  1, 9.9000
  2, 8.8000

but when I try to use the sequence printer

p2.print(std::cout, my_map);

the compiler (VC10) complains the there is no operator<<

I:\boost-sandbox\type_erasure\boost/type_erasure/operators.hpp(422): error C2679: binary '<<' : no
operator found which takes a right-hand operand of type 'const std::pair<_Ty1,_Ty2>' (or there is no
acceptable conversion)
          with
          [
              _Ty1=const int,
              _Ty2=double
          ]

(I've tried several combinations of const or not, const int or int, and pair<K, T> and <K, T>& so I
can't see that this is a const issue or ref issue).

What am I doing wrong?

Paul

PS I'm not sure I understand the base_and_derived and concept_interface structs and how they are
used. Some explanation would be useful for the novice.

---
Paul A. Bristow,
Prizet Farmhouse, Kendal LA8 8AB  UK
+44 1539 561830  07714330204
pbristow_at_[hidden]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk