Message:
This is a really really rough start but I wanted to pass this by you
first.
For C++98/C++03 where there is no standard "move" mechanism, I think we
should use Koenig resolution to allow a gmock client to override the
move function.
With this code change, I can now get the following to compile
class MyMock {
MOCK_METHOD0(TakesOwnership, void(Foo::MoveOnlyType m);
};
Assuming I also declare a
namespace Foo {
MoveOnlyType move(MoveOnlyType m);
}
Please review this at http://codereview.appspot.com/5504122/
Affected files:
M include/gmock/gmock-spec-builders.h
M include/gmock/internal/gmock-port.h
Index: include/gmock/gmock-spec-builders.h
===================================================================
--- include/gmock/gmock-spec-builders.h (revision 374)
+++ include/gmock/gmock-spec-builders.h (working copy)
@@ -1300,6 +1300,10 @@
virtual void PrintAsActionResult(::std::ostream* os) const = 0;
};
+// Allow Koenig resolution of move() so that C++98 gmock users can override
+// with their own impelmentation if they are doing some sort of
+using std::move;
+
// This generic definition is used when T is not void.
template <typename T>
class ActionResultHolder : public UntypedActionResultHolderBase {
@@ -1311,9 +1315,9 @@
// Returns the held value and deletes this object.
T GetValueAndDelete() const {
- T retval(value_);
+ T retval(move(value_));
delete this;
- return retval;
+ return move(retval);
}
// Prints the held value as an action's result to os.
@@ -1344,7 +1348,7 @@
}
private:
- T value_;
+ mutable T value_;
// T could be a reference type, so = isn't supported.
GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
Index: include/gmock/internal/gmock-port.h
===================================================================
--- include/gmock/internal/gmock-port.h (revision 374)
+++ include/gmock/internal/gmock-port.h (working copy)
@@ -75,4 +75,14 @@
#define GMOCK_DEFINE_string_(name, default_val, doc) \
::testing::internal::String GMOCK_FLAG(name) = (default_val)
+// TODO(ajwong): Do something similar to gmock-tuple.h for this to only
enable
+// in C++98 compilers. Also, we might need to make this function smarter
+// using enable_if to switch between a const&, non-const&, and by value
version
+// in C++03.
+namespace std {
+template <typename T>
+T move(T a) { return a; }
+}
+
+
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_