Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-17 18:42:07


"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:004101c4849c$b074dd70$0600a8c0_at_pdimov...
> Jonathan Turkanis wrote:
> > <Arturo_Cuebas_at_[hidden]> wrote in message
> >
news:OF6215D845.F05336EF-ON86256EF3.005F9390-86256EF3.00613932_at_bpmicro.com...

> > I can do it with this syntax:
> >
> > boost::resolve_cast<int()>(&C::g);
> > boost::resolve_cast<int(int)>(&C::g);

> > looks okay to me. My version works on VC7.1, Como 4.3.3 and GCC
3.2.
> > I'll post it if there's interest.
>
> template<class F, class X> F X::* resolve_cast( F X::* pm ) { return
pm; }

Very cool.

> looks like it ought to work. VC 7.1 doesn't like it, though. Neither
does
> GCC 3.2.3.

:(

> The online Comeau compiles it.

Intel 8.0 for windows, too.

I fixed my version, which seems to be reasonably portable (it needs
SFINAE and a certain amount of support for function types). It
consists of an overload for each arity, the first of which looks
something like this:

   template<typename Sig, typename C>
   [ typename result_type<Sig>::type (C::*)() ]
   resolve_cast( result_type<Sig>::type (C::*f)(),
            typename enable_if< Sig has arity 0 >::type* = 0)
  {
      return t;
   }

Jonathan


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