summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2014-12-12 13:46:41 -0800
committerNat Goodspeed <nat@lindenlab.com>2014-12-12 13:46:41 -0800
commiteae38f7d57be5576199294b501e082c6d850473c (patch)
tree2ca2cac78beeb339676d9a405462f3ed83776fa3
parent7282d29bf82deaeb5649b09f062d42c04df6eb55 (diff)
Eliminate use of boost::lambda with boost::function (Trac #10864).
https://svn.boost.org/trac/boost/ticket/10864 I've used boost::lambda with boost::function in a number of creative ways over the years. But the clang 6 shipped with Xcode 6 seems to have somehow broken lambda + function in Boost 1.57. boost::phoenix is a partial workaround. Sadly, lambda's comma-operator overload doesn't seem to be supported, necessitating a couple ugly workarounds. With real lambdas now supported by current compilers, I'm sure the Boost community has little incentive to repair the lambda + function problem. Presumably we'll be able to use such features ourselves Real Soon Now...
-rwxr-xr-xindra/llcommon/tests/llleap_test.cpp10
-rwxr-xr-xindra/llcommon/tests/llsdserialize_test.cpp40
-rwxr-xr-xindra/newview/llwindowlistener.cpp49
3 files changed, 61 insertions, 38 deletions
diff --git a/indra/llcommon/tests/llleap_test.cpp b/indra/llcommon/tests/llleap_test.cpp
index 9ea822cb8d..653b043de4 100755
--- a/indra/llcommon/tests/llleap_test.cpp
+++ b/indra/llcommon/tests/llleap_test.cpp
@@ -17,7 +17,7 @@
// std headers
// external library headers
#include <boost/assign/list_of.hpp>
-#include <boost/lambda/lambda.hpp>
+#include <boost/phoenix/core/argument.hpp>
#include <boost/foreach.hpp>
// other Linden headers
#include "../test/lltut.h"
@@ -109,7 +109,7 @@ namespace tut
llleap_data():
reader(".py",
// This logic is adapted from vita.viewerclient.receiveEvent()
- boost::lambda::_1 <<
+ boost::phoenix::placeholders::arg1 <<
"import re\n"
"import os\n"
"import sys\n"
@@ -403,7 +403,7 @@ namespace tut
AckAPI api;
Result result;
NamedTempFile script("py",
- boost::lambda::_1 <<
+ boost::phoenix::placeholders::arg1 <<
"from " << reader_module << " import *\n"
// make a request on our little API
"request(pump='" << api.getName() << "', data={})\n"
@@ -441,7 +441,7 @@ namespace tut
ReqIDAPI api;
Result result;
NamedTempFile script("py",
- boost::lambda::_1 <<
+ boost::phoenix::placeholders::arg1 <<
"import sys\n"
"from " << reader_module << " import *\n"
// Note that since reader imports llsd, this
@@ -484,7 +484,7 @@ namespace tut
ReqIDAPI api;
Result result;
NamedTempFile script("py",
- boost::lambda::_1 <<
+ boost::phoenix::placeholders::arg1 <<
"import sys\n"
"from " << reader_module << " import *\n"
// Generate a very large string value.
diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp
index b5893135ea..afd4e7c8c1 100755
--- a/indra/llcommon/tests/llsdserialize_test.cpp
+++ b/indra/llcommon/tests/llsdserialize_test.cpp
@@ -46,9 +46,9 @@ typedef U32 uint32_t;
#include "boost/range.hpp"
#include "boost/foreach.hpp"
#include "boost/function.hpp"
-#include "boost/lambda/lambda.hpp"
-#include "boost/lambda/bind.hpp"
-namespace lambda = boost::lambda;
+#include "boost/phoenix/bind/bind_function.hpp"
+#include "boost/phoenix/core/argument.hpp"
+using namespace boost::phoenix;
#include "../llsd.h"
#include "../llsdserialize.h"
@@ -1612,6 +1612,20 @@ namespace tut
"print 'Running on', sys.platform\n");
}
+ // helper for test<3>
+ static void writeLLSDArray(std::ostream& out, const LLSD& array)
+ {
+ BOOST_FOREACH(LLSD item, llsd::inArray(array))
+ {
+ LLSDSerialize::toNotation(item, out);
+ // It's important to separate with newlines because Python's llsd
+ // module doesn't support parsing from a file stream, only from a
+ // string, so we have to know how much of the file to read into a
+ // string.
+ out << '\n';
+ }
+ }
+
template<> template<>
void TestPythonCompatibleObject::test<3>()
{
@@ -1639,26 +1653,16 @@ namespace tut
" assert False, 'Too many data items'\n";
// Create an llsdXXXXXX file containing 'data' serialized to
- // notation. It's important to separate with newlines because Python's
- // llsd module doesn't support parsing from a file stream, only from a
- // string, so we have to know how much of the file to read into a
- // string.
+ // notation.
NamedTempFile file("llsd",
// NamedTempFile's boost::function constructor
// takes a callable. To this callable it passes the
// std::ostream with which it's writing the
- // NamedTempFile. This lambda-based expression
- // first calls LLSD::Serialize() with that ostream,
- // then streams a newline to it, etc.
- (lambda::bind(LLSDSerialize::toNotation, cdata[0], lambda::_1),
- lambda::_1 << '\n',
- lambda::bind(LLSDSerialize::toNotation, cdata[1], lambda::_1),
- lambda::_1 << '\n',
- lambda::bind(LLSDSerialize::toNotation, cdata[2], lambda::_1),
- lambda::_1 << '\n'));
+ // NamedTempFile.
+ bind(writeLLSDArray, placeholders::arg1, cdata));
python("read C++ notation",
- lambda::_1 <<
+ placeholders::arg1 <<
import_llsd <<
"def parse_each(iterable):\n"
" for item in iterable:\n"
@@ -1679,7 +1683,7 @@ namespace tut
NamedTempFile file("llsd", "");
python("write Python notation",
- lambda::_1 <<
+ placeholders::arg1 <<
"from __future__ import with_statement\n" <<
import_llsd <<
"DATA = [\n"
diff --git a/indra/newview/llwindowlistener.cpp b/indra/newview/llwindowlistener.cpp
index a8e06511d7..734018cfc2 100755
--- a/indra/newview/llwindowlistener.cpp
+++ b/indra/newview/llwindowlistener.cpp
@@ -44,10 +44,7 @@
#include <typeinfo>
#include <map>
#include <boost/scoped_ptr.hpp>
-#include <boost/lambda/core.hpp>
-#include <boost/lambda/bind.hpp>
-
-namespace bll = boost::lambda;
+#include <boost/bind.hpp>
LLWindowListener::LLWindowListener(LLViewerWindow *window, const KeyboardGetter& kbgetter)
: LLEventAPI("LLWindow", "Inject input events into the LLWindow instance"),
@@ -358,6 +355,30 @@ static WhichButton buttons;
typedef boost::function<bool(LLCoordGL, MASK)> MouseFunc;
+// Wrap a function returning 'void' to return 'true' instead. I'm sure there's
+// a more generic way to accomplish this, but generically handling the
+// arguments seems to require variadic templates and perfect forwarding. (We
+// used to be able to write (boost::lambda::bind(...), true), counting on
+// boost::lambda's comma operator overload, until
+// https://svn.boost.org/trac/boost/ticket/10864. And boost::phoenix doesn't
+// seem to overload comma the same way; or at least not with bind().)
+class MouseFuncTrue
+{
+ typedef boost::function<void(LLCoordGL, MASK)> MouseFuncVoid;
+ MouseFuncVoid mFunc;
+
+public:
+ MouseFuncTrue(const MouseFuncVoid& func):
+ mFunc(func)
+ {}
+
+ bool operator()(LLCoordGL coords, MASK mask) const
+ {
+ mFunc(coords, mask);
+ return true;
+ }
+};
+
static void mouseEvent(const MouseFunc& func, const LLSD& request)
{
// Ensure we send response
@@ -464,11 +485,11 @@ void LLWindowListener::mouseDown(LLSD const & request)
if (actions.valid)
{
// Normally you can pass NULL to an LLWindow* without compiler
- // complaint, but going through boost::lambda::bind() evidently
+ // complaint, but going through boost::bind() evidently
// bypasses that special case: it only knows you're trying to pass an
// int to a pointer. Explicitly cast NULL to the desired pointer type.
- mouseEvent(bll::bind(actions.down, mWindow,
- static_cast<LLWindow*>(NULL), bll::_1, bll::_2),
+ mouseEvent(boost::bind(actions.down, mWindow,
+ static_cast<LLWindow*>(NULL), _1, _2),
request);
}
}
@@ -478,8 +499,8 @@ void LLWindowListener::mouseUp(LLSD const & request)
Actions actions(buttons.lookup(request["button"]));
if (actions.valid)
{
- mouseEvent(bll::bind(actions.up, mWindow,
- static_cast<LLWindow*>(NULL), bll::_1, bll::_2),
+ mouseEvent(boost::bind(actions.up, mWindow,
+ static_cast<LLWindow*>(NULL), _1, _2),
request);
}
}
@@ -489,12 +510,10 @@ void LLWindowListener::mouseMove(LLSD const & request)
// We want to call the same central mouseEvent() routine for
// handleMouseMove() as for button clicks. But handleMouseMove() returns
// void, whereas mouseEvent() accepts a function returning bool -- and
- // uses that bool return. Use (void-lambda-expression, true) to construct
- // a callable that returns bool anyway. Pass 'true' because we expect that
- // our caller will usually treat 'false' as a problem.
- mouseEvent((bll::bind(&LLWindowCallbacks::handleMouseMove, mWindow,
- static_cast<LLWindow*>(NULL), bll::_1, bll::_2),
- true),
+ // uses that bool return. Use MouseFuncTrue to construct a callable that
+ // returns bool anyway.
+ mouseEvent(MouseFuncTrue(boost::bind(&LLWindowCallbacks::handleMouseMove, mWindow,
+ static_cast<LLWindow*>(NULL), _1, _2)),
request);
}