Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] Detect shared_ptr argument at compile time
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-07-27 12:28:40


On 7/27/2010 3:30 AM, Ralf Globisch wrote:
> Hi,
> I'm not sure if this is the correct mailing list for this question:
>
> Is there a way to determine if a template parameters is of type
> boost::shared_ptr at compile time?
>
> I would like to do something like:
>
> template<class A>
> void doSomething( const A& a)
> {
> // if "a" is of type boost::shared_ptr<SomeType>
> a->someMethod();
> // else
> a.someMethod();
> }
>
> Is this possible at all?
>
> Regards,
> Ralf

Overload on shared_ptr?

template< class A >
void doSomeMethod(const A& a)
{ a.someMethod(); }
template< class A, ... /* remaining shared_ptr template parameters */ ... >
void doSomeMethod(const boost::shared_ptr< A, ... >& a)
{ a->someMethod(); }

template< class A >
void doSomething(const A& a)
{
     doSomeMethod(a);
}

- Jeff


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