|
Boost : |
Subject: [boost] [contract] C++11-like auto-functions
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-06-27 21:20:42
Hello all,
I'm thinking to expand Boost.Contract to support C++11-like
auto-functions for C++03.
The following macro:
CONTRACT_FUNCTION( // f
template( typename Left, typename Right )
auto (adding_func) ( (Left const&) left, (Right const&) right )
return(BOOT_TYPEOF_TPL(left + right))
) {
return left + right;
}
Would expand to something like the code below (but the main of course):
#include <boost/typeof/typeof.hpp>
#include <iostream>
template< typename Left, typename Right > // TPARAMS(f)
struct adding_func_result_123
{
Left const& left; // PARAMS(f)
Right const& right; // PARAMS(f)
typedef
BOOST_TYPEOF_TPL(left + right) // RESULT_TYPE(f)
type
;
};
template< typename Left, typename Right >
typename adding_func_result_123<Left, Right>::type // TPARAMS(f)
adding_func ( Left const& left, Right const& right )
{
return left + right;
}
int main ( void )
{
std::cout << adding_func(1, 2) << std::endl;
return 0;
}
I got a ticket for it: https://sourceforge.net/apps/trac/contractpp/ticket/59
But I might implement it only after the Boost review... (Are C++11
auto-function really useful?)
Thanks.
--Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk