Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2006-09-06 07:29:29

Steven Watanabe wrote:
>Alexander Nasonov,
> Instead of using anyT as the placeholder I think that creating
>separate placeholders for each argument may be better. It allows
>for better checking at compile time when the argument types really
>model different concepts.
>struct to_ostream;
>struct ostream : function_arg<to_ostream, 0> {};
>struct ostreamable : function_arg<to_ostream, 1> {};
>struct to_ostream : function<ostream&(ostream&, ostreamable&)> {
> template<class R, class Os, class T>
> R execute(Os& os, T& t) {
> return(os << t);
> }
>void f() {
> any<ostream> os(ref(cout));
> any<ostreamable> value(1);
> to_ostream()(os, value);

So far I see only that it adds more complexity.
1) You introduced circular dependency between to_ostream operation and arguments
2) The any<> now takes argument wrappers rather than a list of operations

If you need an operation that takes anys of different types why don't you do it in a straightforward manner?

// Interface for storing reference_wrapper<ostream&> objects
typedef any<ostream_ref_operations> ostream_ref;

struct to_ostream
  : function<ostream_ref&(ostream_ref&, anyT const&)>
    // ...

> ... skiped ...
>In Christ,
>Steven Watanabe

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