|
Boost Users : |
Subject: Re: [Boost-users] [Fusion] Output of adapted ADT
From: Tore Halvorsen (tore.halvorsen_at_[hidden])
Date: 2011-04-11 03:29:24
On Mon, Apr 11, 2011 at 1:53 AM, Joel de Guzman
<joel_at_[hidden]> wrote:
> 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/tutorials/karma_adapted_complex.html
... 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<T,N,Const>)'
sw<int> const sw_int(7);
generate(std::ostream_iterator<char>(std::cout), int_ << eol, sw_int);
// this fails with
// boost/spirit/home/support/container.hpp(174): error C2039: 'const_iterator'
// : is not a member of
'boost::fusion::extension::adt_attribute_proxy<T,N,Const>'
// with[T=sw<std::string>,N=0,Const=true]
sw<std::string> const sw_string("foo");
generate(std::ostream_iterator<char>(std::cout), string << eol, sw_string);
}
-- Eld på åren og sol på eng gjer mannen fegen og fjåg. [Jøtul] <demo> 2011 Tore Halvorsen || +052 0553034554
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net