|
Boost : |
From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2002-09-04 04:25:44
The boost::function cannot be used in 'any' because it has arguments of
fixed type. What we need here is function_template:
template<int Id>
struct template_param;
template<typename Return, typename Arg1, typename Arg2, class Functor>
struct function_template;
struct ostream_inserter
{
template<typename Arg1, typename Arg2>
Arg1 operator()(Arg1 os, Arg2 val)
{
BOOST_STATIC_ASSERT(is_reference<Arg1>::value);
os << val;
return os;
}
};
typedef template_param<0> _T;
typedef function_template<ostream &, ostream &, _T,
ostream_inserter> ostream_inserter_template;
function<ostream &, ostream &, char> f =
ostream_inserter_template::bind<_T, char>();
f(cout, '!') << endl;
Or, if used with 'any':
any<ostream_inserter_template> a = '!';
a.call<ostream_inserter_template>(cout) << endl;
-- Best regards, Alexander Nasonov e-mail account: alnsn e-mail server: mail.ru
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk