<<< CTTL_MEMBER_ACTION | Lambda Home | CTTL_STATIC_ACTION >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
Helper macro
CTTL_MEMBER_ACTION_NOARG( obj, mf1 )
instantiates a closure for member function with no arguments.
This macro provides additional tracing for lambda expressions. The tracing is turned on by any of the following preprocessor symbols:
#define CTTL_TRACE_EVERYTHING // by default automatically turns lambda tracing on #define CTTL_TRACE_RULES // by default automatically turns lambda tracing on #define CTTL_TRACE_DEPOSITS // turns lambda tracing on
To turn lambda tracing off while CTTL_TRACE_EVERYTHING or CTTL_TRACE_RULES are in effect,
#define CTTL_TRACE_DEPOSITS_OFF
The parameters are:
obj is an object that implements the member function to be invoked. Note: obj is not a scalar type. Constant objects are passed by const reference; mutable objects - by address.
mf1 is function object acting as member function pointer adaptor. The adaptor is a model of STL adaptable unary function. The mf1 adaptor is usually the result of the helper call std::mem_fun().
Download:
Keywords: closure_mem_noarg.cpp, std::vector, vector::size, std::mem_fun
// closure_mem_noarg.cpp // Program demonstrates calling member function with no arguments. #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main(/*int argc, char* argv[]*/) { int var = 0; std::vector< int > vect( 3 ); ( scalar( &var ) = *scalar( CTTL_MEMBER_ACTION_NOARG( vect, std::mem_fun( &std::vector< int >::size ) )) ).evaluate(); assert( var == 3 ); return 0; }
// int_memfun_noarg.cpp // Program demonstrates calling member functions with no arguments. #define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; struct handler { // member function with no arguments int mf() { return 2; } // constant member function with no arguments int mfc() const { return 3; } }; int main(/*int argc, char* argv[]*/) { int result = 0; lambda< int >::scalar_reference sresult( &result ); handler hand; // calls to member function with no arguments: result = std::mem_fun( &handler::mf )( &hand ); result = std::mem_fun( &handler::mfc )( &hand ); ( sresult = *scalar( CTTL_MEMBER_ACTION_NOARG( &hand, std::mem_fun( &handler::mf ) // or mfc ) ) , CTTL_LAMBDA_ASSERT( sresult == 2 ) , sresult = *scalar( CTTL_MEMBER_ACTION_NOARG( &hand, std::mem_fun( &handler::mfc ) // or mfc ) ) , CTTL_LAMBDA_ASSERT( sresult == 3 ) ).evaluate(); return 0; }
// void_memfun_noarg.cpp // Program demonstrates calling void member functions with no arguments. #define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; struct handler { // void member function with no arguments void vmf() { } // constant void member function with no arguments void vmfc() const { } }; int main(/*int argc, char* argv[]*/) { lambda< int >::scalar sresult; handler hand; // calls to member function with no arguments: std::mem_fun( &handler::vmf )( &hand ); std::mem_fun( &handler::vmfc )( &hand ); ( sresult = *scalar( CTTL_MEMBER_ACTION_NOARG( &hand, std::mem_fun( &handler::vmf ) ) ) , CTTL_LAMBDA_ASSERT( sresult == 1 ) , sresult = *scalar( CTTL_MEMBER_ACTION_NOARG( &hand, std::mem_fun( &handler::vmfc ) ) ) , CTTL_LAMBDA_ASSERT( sresult == 1 ) ).evaluate(); return 0; }
Copyright © 1997-2009 Igor Kholodov mailto:cttl@users.sourceforge.net.
Permission to copy and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
<<< CTTL_MEMBER_ACTION | Lambda Home | CTTL_STATIC_ACTION >>> |