@@ -102,7 +102,7 @@ typename std::enable_if<butil::is_void<Ret>::value, Ret>::type ReturnEmpty() {}
102102 template <typename ... Args> \
103103 typename std::enable_if<decltype ( \
104104 Test<class_type, Args...>(0 ))::value, return_type>::type \
105- Call (class_type* obj, Args... args) { \
105+ Call (class_type* obj, Args&& ... args) { \
106106 BAIDU_CASSERT ((butil::is_result_same< \
107107 return_type, decltype (&T::func_name), T, Args...>::value), \
108108 " Params or return type mismatch" ); \
@@ -112,7 +112,7 @@ typename std::enable_if<butil::is_void<Ret>::value, Ret>::type ReturnEmpty() {}
112112 template <typename ... Args> \
113113 typename std::enable_if<!decltype ( \
114114 Test<class_type, Args...>(0 ))::value, return_type>::type \
115- Call (class_type* obj, Args... args) { \
115+ Call (class_type* obj, Args&& ... args) { \
116116 return ReturnEmpty<return_type>(); \
117117 } \
118118 }
@@ -128,13 +128,13 @@ typename std::enable_if<butil::is_void<Ret>::value, Ret>::type ReturnEmpty() {}
128128//
129129// CRTP
130130// Derived classes implement 6 functions :
131- // 1. (required) int OnCreated(Args... args) :
131+ // 1. (required) int OnCreated(Args&& ... args) :
132132// Will be called in Create() to initialize T init when T is created successfully.
133133// If initialization fails, return non-zero. VersionedRefWithId will be `SetFailed'
134134// and Create() returns non-zero.
135135// 2. (required) void BeforeRecycled() :
136136// Will be called in Dereference() before T is recycled.
137- // 3. (optional) void OnFailed(Args... args) :
137+ // 3. (optional) void OnFailed(Args&& ... args) :
138138// Will be called in SetFailed() when VersionedRefWithId is set failed successfully.
139139// 4. (optional) void BeforeAdditionalRefReleased() :
140140// Will be called in ReleaseAdditionalReference() before additional ref is released.
@@ -212,7 +212,7 @@ class VersionedRefWithId {
212212 // `args' will be passed to OnCreated() directly.
213213 // Returns 0 on success, -1 otherwise.
214214 template <typename ... Args>
215- static int Create (VRefId* id, Args... args);
215+ static int Create (VRefId* id, Args&& ... args);
216216
217217 // Place the VersionedRefWithId associated with identifier `id' into
218218 // unique_ptr `ptr', which will be released automatically when out
@@ -246,10 +246,10 @@ class VersionedRefWithId {
246246 // This function is lock-free.
247247 // Returns -1 when the Socket was already SetFailed(), 0 otherwise.
248248 template <typename ... Args>
249- static int SetFailedById (VRefId id, Args... args);
249+ static int SetFailedById (VRefId id, Args&& ... args);
250250
251251 template <typename ... Args>
252- int SetFailed (Args... args);
252+ int SetFailed (Args&& ... args);
253253
254254 bool Failed () const {
255255 return VersionOfVRef (_versioned_ref.load (butil::memory_order_relaxed))
@@ -290,7 +290,7 @@ friend void DereferenceVersionedRefWithId<>(T* r);
290290 }
291291
292292 template <typename ... Args>
293- int SetFailedImpl (Args... args);
293+ int SetFailedImpl (Args&& ... args);
294294
295295 // Release the reference. If no one is addressing this VersionedRefWithId,
296296 // it will be recycled automatically and T::BeforeRecycled() will be called.
@@ -351,7 +351,7 @@ void DereferenceVersionedRefWithId(T* r) {
351351
352352template <typename T>
353353template <typename ... Args>
354- int VersionedRefWithId<T>::Create(VRefId* id, Args... args) {
354+ int VersionedRefWithId<T>::Create(VRefId* id, Args&& ... args) {
355355 resource_id_t slot;
356356 T* const t = butil::get_resource (&slot, Forbidden ());
357357 if (t == NULL ) {
@@ -458,7 +458,7 @@ void VersionedRefWithId<T>::ReAddress(VersionedRefWithIdUniquePtr<T>* ptr) {
458458
459459template <typename T>
460460template <typename ... Args>
461- int VersionedRefWithId<T>::SetFailedById(VRefId id, Args... args) {
461+ int VersionedRefWithId<T>::SetFailedById(VRefId id, Args&& ... args) {
462462 VersionedRefWithIdUniquePtr<T> ptr;
463463 if (Address (id, &ptr) != 0 ) {
464464 return -1 ;
@@ -468,13 +468,13 @@ int VersionedRefWithId<T>::SetFailedById(VRefId id, Args... args) {
468468
469469template <typename T>
470470template <typename ... Args>
471- int VersionedRefWithId<T>::SetFailed(Args... args) {
471+ int VersionedRefWithId<T>::SetFailed(Args&& ... args) {
472472 return SetFailedImpl (std::forward<Args>(args)...);
473473}
474474
475475template <typename T>
476476template <typename ... Args>
477- int VersionedRefWithId<T>::SetFailedImpl(Args... args) {
477+ int VersionedRefWithId<T>::SetFailedImpl(Args&& ... args) {
478478 const uint32_t id_ver = VersionOfVRefId (_this_id);
479479 uint64_t vref = _versioned_ref.load (butil::memory_order_relaxed);
480480 for (;;) {
0 commit comments