|
Boost : |
Subject: Re: [boost] Review Request: Variadic Macro Data library
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-02-20 14:21:54
On Sun, Feb 20, 2011 at 1:55 PM, Edward Diener <eldiener_at_[hidden]> wrote:
> Fair enough. But I believe some other proposed Boost libraries, besides my
> own TTI library, are using variadic macro syntax in their public interface.
> Why should they not do that and take advantage of pp-lib at the same time ?
For example, Boost.Local new syntax takes advantage of variadics.
If variadics (using a couple of Edward's VMD library macros behind the scenes):
#include <boost/local/function.hpp>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
int main () {
std::ostringstream output;
int BOOST_LOCAL_FUNCTION_PARAMS(int n, bool recursion, default false,
bind& output) {
int result = 0;
if (n < 2 ) result = 1;
else result = n * factorial(n - 1, true); // Recursive call.
if (!recursion) output << result << " ";
return result;
} BOOST_LOCAL_FUNCTION_NAME(factorial)
std::vector<int> v(3);
v[0] = 1; v[1] = 4; v[2] = 7;
std::for_each(v.begin(), v.end(), factorial);
std::cout << output.str() << std::endl;
return 0;
}
In any case (variadics or not):
#include <boost/local/function.hpp>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
int main () {
std::ostringstream output;
int BOOST_LOCAL_FUNCTION_PARAMS( (int n) (bool recursion)(default false)
(bind& output) ) {
int result = 0;
if (n < 2 ) result = 1;
else result = n * factorial(n - 1, true); // Recursive call.
if (!recursion) output << result << " ";
return result;
} BOOST_LOCAL_FUNCTION_NAME(factorial)
std::vector<int> v(3);
v[0] = 1; v[1] = 4; v[2] = 7;
std::for_each(v.begin(), v.end(), factorial);
std::cout << output.str() << std::endl;
return 0;
}
P.S. I just go this to compile :))
-- Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk