Skip to content

Commit

Permalink
dnk
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed Apr 21, 2024
1 parent 2fbb239 commit bcaef5e
Show file tree
Hide file tree
Showing 2 changed files with 241 additions and 100 deletions.
12 changes: 10 additions & 2 deletions include/fakeit/StubbingProgress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,23 @@ namespace fakeit {

template<typename T>
MethodStubbingProgress<R, arglist...>& ReturnCapture(T&& r) {
auto store = std::make_shared<typename std::remove_reference<R>::type>(std::forward<T>(r));
static_assert(std::is_constructible<
typename std::remove_cv<typename std::remove_reference<R>::type>::type&,
typename std::remove_cv<typename std::remove_reference<T>::type>::type&>::value,
"The type captured by ReturnCapture() (named T) must be compatible with the return type of the function (named R), i.e. T t{...}; R& r = t; must compile without creating temporaries.");
auto store = std::make_shared<typename std::remove_cv<typename std::remove_reference<T>::type>::type>(std::forward<T>(r));
return Do([store](const typename fakeit::test_arg<arglist>::type...) mutable -> R {
return std::forward<R>(*store);
});
}

template<typename T>
void AlwaysReturnCapture(T&& r) {
auto store = std::make_shared<typename std::remove_reference<R>::type>(std::forward<T>(r));
static_assert(std::is_constructible<
typename std::remove_cv<typename std::remove_reference<R>::type>::type&,
typename std::remove_cv<typename std::remove_reference<T>::type>::type&>::value,
"The type captured by AlwaysReturnCapture() (named T) must be compatible with the return type of the function (named R), i.e. T t{...}; R& r = t; must compile without creating temporaries.");
auto store = std::make_shared<typename std::remove_cv<typename std::remove_reference<T>::type>::type>(std::forward<T>(r));
return AlwaysDo([store](const typename fakeit::test_arg<arglist>::type...) mutable -> R {
return std::forward<R>(*store);
});
Expand Down
Loading

0 comments on commit bcaef5e

Please sign in to comment.