
Hi Perhaps this would have been better as two separate mails but since it is all lambda related I have included it as one (despite one patch actually being to the result_of library). [lambda] I discovered recently that member-function-ptrs wrapped in boost::lambda objects do not apply directly if the subject is held in a smart-ptr (unless that smart-ptr has an implicit conversion to T*). There are a number of places in our code base where we have worked around this by using something like *free1 rather than simply free1 which ends up calling the 'apply member-function to object-by-reference' adaptor. This works providing the smart-ptr defines a type 'element_type' to be the underlying object type (as shared_ptr et al do). It does not work for third-party smart-ptrs that do not define this type. It struck me that since boost.bind uses boost.mem_fn's get_pointer template to handle this use case it would be reasonable to add an overload of 'apply' to lambda/detail/function_adaptors.hpp that deferred to that. I knocked up a perl script which adds the necessary overloads to each specialization in function_adaptors which I have attached (I have also attached the resulting diff). It may be that this yields some unpleasant side-effects that I haven't thought of or observed but so far it seems to work okay with our code base. The get_pointer overload is disabled if the argument is convertible to ref-to-const-object-type (e.g. if it is a derived type) since then the reference overload should be used. I would appreciate any feedback on the idea and implementation. [result_of] Whilst implementing a front-end template for a set of functions that accept boost.function objects with various return types, I discovered that boost.result_of does not implement support for the nested sig<tuple> template used by boost.lambda objects. My intent was to accept any user-supplied function at the front-end and, based on the given function's return type when applied to a specific set of arguments, forward to the appropriate implementation. This determination currently fails if the user supplies a lambda object. The attached result_of patch adds detection of the nested sig template in order to support determining the return type of lambda functions (providing the necessary arguments are given). This is done in a non-intrusive way; i.e. there is no physical dependency on boost.lambda or boost.tuple, though the boost.tuple classes 'cons' and 'null_type' are forward declared. Since they are only ever instantiated when a boost.lambda object is provided (which will have already brought in their definitions) I think it should be okay. In order to provide the sig template with its required tuple, a facility has been added (with implementation generated by some additional preprocessor code) that converts from function-type to tuple (i.e. F(A,B...) -> cons<F,cons<A, cons<B,...null_type>>>). Since only the type declarations are required this can be done without pulling in any tuple headers. One thing I am a little concerned about is that the determination mechanism for the existence of the sig template is probably not very portable (I have only tried it on GCC 4 and VC9). Is there an MPL/type_traits predicate generator for portable nested template detection? I am aware of BOOST_MPL_HAS_XXX_TRAIT_(NAMED_)DEF but I couldn't see any generator around that area that would do nested template detection. We have such a facility in our code base but it will have only been tried on GCC 4 and VC9 (maybe also VC7.1). Again I would appreciate any feedback on these diffs and whether or not they are suitable for inclusion into the respective libraries. Regards, Adam

AMDG Adam Butcher wrote:
Perhaps this would have been better as two separate mails but since it is all lambda related I have included it as one (despite one patch actually being to the result_of library).
<snip> Is there an MPL/type_traits predicate generator for portable nested template detection? I am aware of BOOST_MPL_HAS_XXX_TRAIT_(NAMED_)DEF but I couldn't see any generator around that area that would do nested template detection. We have such a facility in our code base but it will have only been tried on GCC 4 and VC9 (maybe also VC7.1).
See http://svn.boost.org/trac/boost/ticket/861 and http://svn.boost.org/trac/boost/ticket/864
Again I would appreciate any feedback on these diffs and whether or not they are suitable for inclusion into the respective libraries.
In Christ, Steven Watanabe

On Thu, Apr 1, 2010 at 2:11 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Adam Butcher wrote:
Perhaps this would have been better as two separate mails but since it is all lambda related I have included it as one (despite one patch actually being to the result_of library).
<snip> Is there an MPL/type_traits predicate generator for portable nested template detection? I am aware of BOOST_MPL_HAS_XXX_TRAIT_(NAMED_)DEF but I couldn't see any generator around that area that would do nested template detection. We have such a facility in our code base but it will have only been tried on GCC 4 and VC9 (maybe also VC7.1).
As I recall, much of the code here was meant as infrastructure to support general template introspection; i.e. detecting member class templates and function templates in addition to the member types and variables detected by has_xxx. At the time there didn't seem to be much demand, so I set the project aside. If you're only concerned with detecting member class templates, I'm sure there's more straight forward implementations around that don't rely as heavily on preprocessor metaprogramming.
This patch seemed to be missing, so I re-uploaded it. The patch was the result of (no pun intended) some discussion. I found an e-mail with an overview here http://tinyurl.com/2jgtld. To my knowledge, the patch was never applied. It's been a few years, but my recollection is that a rewrite of lambda was anticipated, which would address these issues, and there was little demand for result_of/lambda compatibility in the meantime. Also, there was no active maintainer for the lambda library. ~Daniel

On Thu, Apr 1, 2010 at 2:38 PM, Daniel Walker <daniel.j.walker@gmail.com> wrote:
This patch seemed to be missing, so I re-uploaded it. The patch was the result of (no pun intended) some discussion. I found an e-mail with an overview here http://tinyurl.com/2jgtld. To my knowledge, the patch was never applied. It's been a few years, but my recollection is that a rewrite of lambda was anticipated, which would address these issues, and there was little demand for result_of/lambda compatibility in the meantime. Also, there was no active maintainer for the lambda library.
Actually, Boost.Phoenix I think is what will completely replace Lambda, have you tried using it, does it have that same problem?

On Fri, Apr 2, 2010 at 9:32 PM, OvermindDL1 <overminddl1@gmail.com> wrote:
On Thu, Apr 1, 2010 at 2:38 PM, Daniel Walker <daniel.j.walker@gmail.com> wrote:
This patch seemed to be missing, so I re-uploaded it. The patch was the result of (no pun intended) some discussion. I found an e-mail with an overview here http://tinyurl.com/2jgtld. To my knowledge, the patch was never applied. It's been a few years, but my recollection is that a rewrite of lambda was anticipated, which would address these issues, and there was little demand for result_of/lambda compatibility in the meantime. Also, there was no active maintainer for the lambda library.
Actually, Boost.Phoenix I think is what will completely replace Lambda, have you tried using it, does it have that same problem?
Phoenix may be used in some eventual rewrite, but that's not the immediate issue. By the way, boost::result_of does work with lambda functors when decltype is available. So, going forward, this will only be an issue on legacy compilers that lack decltype. ~Daniel
participants (4)
-
Adam Butcher
-
Daniel Walker
-
OvermindDL1
-
Steven Watanabe