Boost logo

Boost :

From: Brian Braatz (brianb_at_[hidden])
Date: 2004-12-22 11:03:01


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