[prev in list] [next in list] [prev in thread] [next in thread]
List: boost-users
Subject: Re: [Boost-users] Returning a shared_ptr or raw pointer from a
From: Steven Watanabe <watanabesj () gmail ! com>
Date: 2009-03-31 3:18:52
Message-ID: 49D18B9C.7070109 () providere-consulting ! com
[Download RAW message or body]
AMDG
Ryan McConnehey wrote:
> I would like to have a class that has this create function and upon
> creation of the class specify if the create function returns a raw
> pointer or shared_ptr.
>
> template <class U> //The U specifies is the create function returns a
> raw or shared pointer
> class Rdi
> {
> template <class S>
> U create(void)
> {
> U temp(new S());
> return temp;
> }
> };
>
> How would I modify this class to allow the user to make the following
> calls?
>
> Rdi<boost::shared_ptr> fun1;
This won't compile because boost::shared_ptr is a class template.
> Tm* tm3 = fun1.create<Tm>();
>
> Rdi<raw Pointer???> fun2;
> boost::shared_ptr<Tm> tm4 = fun2.create<Tm>();
>
> Any help would be appreciated.
Try
#include <boost/mpl/apply.hpp>
#include <boost/type_traits/add_pointer.hpp>
#include <boost/shared_ptr.hpp>
template<class U>
class Rdi {
typedef typename boost::mpl::apply<U, Rdi>::type ptr_type;
template<class S>
ptr_type create();
};
Rdi<boost::shared_ptr<boost::mpl::_1> > fun1;
Rdi<boost::add_pointer<boost::mpl::_1> > fun2;
In Christ,
Steven Watanabe
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic