Boost logo

Boost :

From: Brian Braatz (brianb_at_[hidden])
Date: 2004-12-24 12:58:49


> -----Original Message-----
> On Behalf Of Arkadiy Vertleyb
> "Brian Braatz" <brianb_at_[hidden]> wrote
>
> > Is is possible to, given a functor generated as a result of a lambda
> > bind expression, pull the return type from the lambda functor?
>
> I am wondering if "result_of" may be something that you are looking
for.
> OTOH, I don't really know what the status of this library is.
>
> Regards

Thank you for your thoughts- result_of looks like what I want - but I am
having difficultly figuring out what the lamda factor LOOKS like after
it is compile time generated. (I am (very very) slowly dissecting lambda
bind to try to figure this out).

IF ANYONE knows the answer to how you would GET TO result_of syntax wise
help would be appreciated.

(previous mail with sample code below)

-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Brian Braatz
Sent: Wednesday, December 22, 2004 8:03 AM
To: boost_at_[hidden]
Subject: [boost] Help \ Advice requested on getting the return type from
aLambda fctor

I wrote up the simple example that shows what I am trying to figure out

Basically, I am trying to pull the deduced return type (or explicitly
passed as a template param in lambda bind()) in my template.

If I have a function that is receiving a functor, I would like to be
able to take that functor and pull the RETURN TYPE out of it.

      Lets say I have a function that returns a string:

         std::string ReturnAString()
      {
            return "this is a string";
      }

      And then here is my template function (code below does not
compile)

      template < typename TFUNCTOR>
      TFUNCTOR::result_type CallFctorDeduceRet( TFUNCTOR & functor)
      {
            return functor();
      }

 

      Now here is my bind call
        std::cout << ( bind<std::string>(&ReturnAString));

       Is there a way to GET to the return type in the Lambda fctor that
was generated with a BIND call? I would like to be able to pull the
<std::string> from the bind call and use it in the template function. It
is not a problem for my template function to be dependant upon lambda
bind.

      I have been going through the lambda code. And while it is
brilliant, I am having a bit of difficulty figuring out what I am
looking at (grin).

 
Any help or direction is greatly appreciated
FULL SAMPLE CODE HERE:

      template <typename CURRIEDTYPE>
      // Id class for currying type without creating the object
      class Id
      {
            public:

                  typedef CURRIEDTYPE TYPE;

      };

      // Explictly pass IN a return type
      template < typename TFUNCTOR, typename TRET>
      TRET CallFctorPassInRet ( TFUNCTOR & functor, Id<TRET> & )
      {
            Id<TRET>::TYPE TRet;

            TRet = functor();

            return TRet;

      }
      std::string ReturnAString()
      {
            return "this is a string";
      }

      // try to get return type from the lambda fctor
      // Below does not compile- but it is along the lines of what I
      // WANT to do- note that I am trying to get from the Lambda
functor the deduced return type

      template < typename TFUNCTOR>
      TFUNCTOR::result_type CallFctorDeduceRet( TFUNCTOR & functor)
      {
            return functor();
      }

      void Test_LambdaRetDeduction()
      {

            std::cout << "CallFctorPassInRet returns [" <<
CallFctorPassInRet( bind(&ReturnAString), Id<std::string>()) << "]" <<
std::endl;

            // below is what I want to make work
             std::cout << "CallFctorDeduceRet returns [" <<
CallFctorDeduceRet( bind<std::string>(&ReturnAString)) << "]" <<
std::endl;

            }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk