1 // PR tree-optimization/56029
7 void operator () (T * ptr) { delete ptr; }
9 template <class T, class D>
10 struct scoped_ptr_impl
12 scoped_ptr_impl (T * p):data_ (p) {}
13 template <typename U, typename V>
14 scoped_ptr_impl (scoped_ptr_impl <U, V> *other):data_ (other->release (), get_deleter ()) {}
15 ~scoped_ptr_impl () { static_cast <D> (data_) (data_.ptr); }
16 void reset (T * p) { data_.ptr = p; }
18 T *release () { data_.ptr = __null; }
22 Data (T *) : ptr () {}
23 Data (T *, D) : D (), ptr () {}
28 template <class T, class D = DefaultDeleter <T> >
33 RValue (scoped_ptr * object):object (object) {}
36 scoped_ptr Pass () { return scoped_ptr ((this)); }
37 typedef T element_type;
38 typedef D deleter_type;
39 scoped_ptr () : impl_ (__null) {}
40 scoped_ptr (RValue rvalue) : impl_ (&rvalue.object->impl_) {}
41 void reset (element_type * p) { impl_.reset (p); }
42 scoped_ptr_impl <element_type, deleter_type> impl_;
46 struct ClientSocketFactory;
47 struct DatagramClientSocket;
50 scoped_ptr <DatagramClientSocket> CreateConnectedSocket ();
51 ClientSocketFactory *socket_factory_;
53 int RandInt (int, int);
54 struct BindStateBase {};
57 CallbackBase (BindStateBase *);
60 template <typename, typename, typename>
62 template <typename R, typename A1, typename A2>
63 struct Callback <R (A1, A2)> : CallbackBase
65 template <typename Runnable, typename BindRunType, typename BoundArgsType>
66 Callback (BindState <Runnable, BindRunType, BoundArgsType> *bind_state) : CallbackBase (bind_state) {}
68 typedef Callback <int (int, int)>
70 struct ClientSocketFactory
72 virtual DatagramClientSocket *CreateDatagramClientSocket (RandIntCallback) = 0;
75 struct RunnableAdapter;
76 template <typename R, typename A1, typename A2>
77 struct RunnableAdapter <R (*) (A1, A2)>
79 typedef R (RunType) (A1, A2);
84 typedef RunnableAdapter <T> RunnableType;
85 typedef typename RunnableType::RunType RunType;
88 typename FunctorTraits <T>::RunnableType MakeRunnable (T)
91 template <int, typename, typename>
93 template <typename StorageType, typename R, typename X1, typename X2>
94 struct Invoker <0, StorageType, R (X1, X2)>
96 typedef R (UnboundRunType) (X1, X2);
98 template <typename Runnable, typename RunType>
99 struct BindState <Runnable, RunType, void ()> : BindStateBase
101 typedef Runnable RunnableType;
102 typedef Invoker <0, BindState, RunType> InvokerType;
103 typedef typename InvokerType::UnboundRunType UnboundRunType;
104 BindState (Runnable):runnable_ () {}
105 RunnableType runnable_;
107 template <typename Functor>
108 Callback <typename BindState <typename FunctorTraits <Functor>::RunnableType, typename FunctorTraits <Functor>::RunType, void ()>::UnboundRunType>
109 Bind (Functor functor)
111 typedef typename FunctorTraits <Functor>::RunnableType RunnableType;
112 typedef typename FunctorTraits <Functor>::RunType RunType;
113 typedef BindState <RunnableType, RunType, void ()> BindState;
114 Callback <typename BindState::UnboundRunType> (new BindState (MakeRunnable (functor)));
116 struct DatagramClientSocket
118 virtual ~ DatagramClientSocket ();
120 scoped_ptr <DatagramClientSocket>
121 DnsSocketPool::CreateConnectedSocket ()
123 scoped_ptr <DatagramClientSocket> socket;
124 socket.reset (socket_factory_->CreateDatagramClientSocket (Bind (RandInt)));