@@ -52,7 +52,8 @@ namespace fakeit {
5252 /* *
5353 * Return the original method. not the mock.
5454 */
55- virtual typename std::function<R(arglist&...)> getOriginalMethod () = 0;
55+ virtual typename std::function<R(arglist&...)> getOriginalMethodCopyArgs () = 0;
56+ virtual typename std::function<R(arglist&...)> getOriginalMethodForwardArgs () = 0;
5657
5758 virtual std::string getMethodName () = 0;
5859
@@ -153,8 +154,12 @@ namespace fakeit {
153154 into.push_back (&getStubbingContext ().getInvolvedMock ());
154155 }
155156
156- typename std::function<R(arglist &...)> getOriginalMethod () {
157- return getStubbingContext ().getOriginalMethod ();
157+ typename std::function<R(arglist &...)> getOriginalMethodCopyArgs () {
158+ return getStubbingContext ().getOriginalMethodCopyArgs ();
159+ }
160+
161+ typename std::function<R(arglist &...)> getOriginalMethodForwardArgs () {
162+ return getStubbingContext ().getOriginalMethodForwardArgs ();
158163 }
159164
160165 void setInvocationMatcher (typename ActualInvocation<arglist...>::Matcher *matcher) {
@@ -222,13 +227,13 @@ namespace fakeit {
222227 _impl->setMethodDetails (mockName, methodName);
223228 }
224229
225- void setMatchingCriteria (std::function<bool (arglist &...)> predicate) {
230+ void setMatchingCriteria (const std::function<bool (arglist &...)>& predicate) {
226231 typename ActualInvocation<arglist...>::Matcher *matcher{
227232 new UserDefinedInvocationMatcher<arglist...>(predicate)};
228233 _impl->setInvocationMatcher (matcher);
229234 }
230235
231- void setMatchingCriteria (const std::vector<Destructible *> &matchers) {
236+ void setMatchingCriteria (std::vector<Destructible *> &matchers) {
232237 typename ActualInvocation<arglist...>::Matcher *matcher{
233238 new ArgumentsMatcherInvocationMatcher<arglist...>(matchers)};
234239 _impl->setInvocationMatcher (matcher);
@@ -245,21 +250,26 @@ namespace fakeit {
245250 _impl->setMethodBodyByAssignment (method);
246251 }
247252
248- template <class ...matcherCreators, class = typename std::enable_if<
249- sizeof ...(matcherCreators) == sizeof ...(arglist)>::type>
250- void setMatchingCriteria (const matcherCreators &... matcherCreator) {
253+ template <class ...matcherCreators>
254+ typename std::enable_if< //
255+ sizeof ...(matcherCreators) == sizeof ...(arglist), void > //
256+ ::type setMatchingCriteria (matcherCreators &&... matcherCreator) {
251257 std::vector<Destructible *> matchers;
252258
253259 MatchersCollector<0 , arglist...> c (matchers);
254- c.CollectMatchers (matcherCreator...);
260+ c.CollectMatchers (std::forward<matcherCreators>( matcherCreator) ...);
255261
256262 MethodMockingContext<R, arglist...>::setMatchingCriteria (matchers);
257263 }
258264
259265 private:
260266
261- typename std::function<R(arglist&...)> getOriginalMethod () override {
262- return _impl->getOriginalMethod ();
267+ typename std::function<R(arglist&...)> getOriginalMethodCopyArgs () override {
268+ return _impl->getOriginalMethodCopyArgs ();
269+ }
270+
271+ typename std::function<R(arglist&...)> getOriginalMethodForwardArgs () override {
272+ return _impl->getOriginalMethodForwardArgs ();
263273 }
264274
265275 std::shared_ptr<Implementation> _impl;
@@ -287,18 +297,13 @@ namespace fakeit {
287297 return *this ;
288298 }
289299
290- MockingContext<R, arglist...> &Using (const arglist &... args) {
291- MethodMockingContext<R, arglist...>::setMatchingCriteria (args...);
292- return *this ;
293- }
294-
295300 template <class ...arg_matcher>
296- MockingContext<R, arglist...> &Using (const arg_matcher &... arg_matchers) {
297- MethodMockingContext<R, arglist...>::setMatchingCriteria (arg_matchers...);
301+ MockingContext<R, arglist...> &Using (arg_matcher & &... arg_matchers) {
302+ MethodMockingContext<R, arglist...>::setMatchingCriteria (std::forward<arg_matcher>( arg_matchers) ...);
298303 return *this ;
299304 }
300305
301- MockingContext<R, arglist...> &Matching (std::function<bool (arglist &...)> matcher) {
306+ MockingContext<R, arglist...> &Matching (const std::function<bool (arglist &...)>& matcher) {
302307 MethodMockingContext<R, arglist...>::setMatchingCriteria (matcher);
303308 return *this ;
304309 }
@@ -308,7 +313,7 @@ namespace fakeit {
308313 return *this ;
309314 }
310315
311- MockingContext<R, arglist...> &operator ()(std::function<bool (arglist &...)> matcher) {
316+ MockingContext<R, arglist...> &operator ()(const std::function<bool (arglist &...)>& matcher) {
312317 MethodMockingContext<R, arglist...>::setMatchingCriteria (matcher);
313318 return *this ;
314319 }
@@ -352,18 +357,13 @@ namespace fakeit {
352357 return *this ;
353358 }
354359
355- MockingContext<void , arglist...> &Using (const arglist &... args) {
356- MethodMockingContext<void , arglist...>::setMatchingCriteria (args...);
357- return *this ;
358- }
359-
360360 template <class ...arg_matcher>
361- MockingContext<void , arglist...> &Using (const arg_matcher &... arg_matchers) {
362- MethodMockingContext<void , arglist...>::setMatchingCriteria (arg_matchers...);
361+ MockingContext<void , arglist...> &Using (arg_matcher & &... arg_matchers) {
362+ MethodMockingContext<void , arglist...>::setMatchingCriteria (std::forward<arg_matcher>( arg_matchers) ...);
363363 return *this ;
364364 }
365365
366- MockingContext<void , arglist...> &Matching (std::function<bool (arglist &...)> matcher) {
366+ MockingContext<void , arglist...> &Matching (const std::function<bool (arglist &...)>& matcher) {
367367 MethodMockingContext<void , arglist...>::setMatchingCriteria (matcher);
368368 return *this ;
369369 }
@@ -373,7 +373,7 @@ namespace fakeit {
373373 return *this ;
374374 }
375375
376- MockingContext<void , arglist...> &operator ()(std::function<bool (arglist &...)> matcher) {
376+ MockingContext<void , arglist...> &operator ()(const std::function<bool (arglist &...)>& matcher) {
377377 MethodMockingContext<void , arglist...>::setMatchingCriteria (matcher);
378378 return *this ;
379379 }
0 commit comments