Boost logo

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:

    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)
        BOOST_TYPEOF_TPL(left + right) // RESULT_TYPE(f)

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:
But I might implement it only after the Boost review... (Are C++11
auto-function really useful?)


Boost list run by bdawes at, gregod at, cpdaniel at, john at