Boost logo

Boost :

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

> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Steven
> Watanabe
> Sent: Wednesday, August 08, 2012 3:29 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] [type_erasure] Review started (July 18-27, 2012)

namespace boost {
namespace type_erasure {

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

// Partial specialization of struct ostreamable for pair<T1, T2>:
template<class Os, typename T1, typename T2>
struct ostreamable<Os, std::pair<T1, T2> >
    static void apply(Os& out, const std::pair<T1, T2>& arg)
      out << arg;
} // namespace type_erasure
} // namespace boost

Works nicely for anything needing std::pair like map.

Followers of this thread may also be amused to see my fumblings with type_erasure (attached)

adding a few more bells and whistles and

using with lots of types of things (including User defined types) in various containers.

I can see lots of neat applications just printing things in containers.


PS I note in fiddling with cosmetic details that boost::tuple only provides a char option for

std::cout << set_open('[') << set_delimiter('_') << set_close(']') << std::endl;

this prevents, for example ", " (comma and space) as a delimiter.

Can anyone remember a good reason why a std::string is not also provided?

Boost list run by bdawes at, gregod at, cpdaniel at, john at