
On Mon, Apr 11, 2011 at 1:53 AM, Joel de Guzman
On 4/9/2011 3:39 PM, TONGARI wrote:
Do you have any suggestion for using adapted class with Spirit that the OP wants to do?
Well, given the current API, you can write:
std::cout << boost::fusion::front(f).get() << std::endl;
Yeah, this works, but I'm still having trouble with karma.
I see that the documentation uses doubles and bools as an example
http://www.boost.org/doc/libs/1_46_1/libs/spirit/doc/html/spirit/karma/tutor...
... but I cannot get ints and strings to work. Am I missing something obvious?
template<typename T>
class sw // simple_wrapper
{
public:
sw(T tp) : t(tp) {}
T const& get() const { return t; }
void set(T const& tp) { t = tp; }
private:
T t;
};
BOOST_FUSION_ADAPT_TPL_ADT(
(T), (sw)(T),
(T const&, T const&, obj.get(), obj.set(val))
);
int main()
{
using namespace boost::spirit::karma;
// this works
sw<bool> const sw_bool(false);
generate(std::ostream_iterator<char>(std::cout), bool_ << eol, sw_bool);
// this works
sw<double> const sw_double(7.7);
generate(std::ostream_iterator<char>(std::cout), double_ << eol, sw_double);
// this fails with
// boost/spirit/home/karma/numeric/detail/numeric_utils.hpp(61):
error C2668: 'fabs' : ambiguous call to overloaded function
// VC\include\math.h(565): could be 'long double fabs(long double)'
// VC\include\math.h(517): or 'float fabs(float)'
// VC\include\math.h(118): or 'double fabs(double)' [found
using argument-dependent lookup]
// while trying to match the argument list
'(boost::fusion::extension::adt_attribute_proxy