Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-03-11 13:47:02


Matthew Vogt wrote:

> I realise this is getting out of hand,

indeed :-)

> but you get can around this
> with two layers of implicit conversion :)
> Like this (I know the real code is templated, this is just
> illustration):
>
> // return type for boost::io::get
> struct character : public boost::spirit::safe_bool<character>
> {
> // return type for filter::get
> struct value_type
> {
> value_type(const character& src) : c(src.value()) {}
>
> operator char() const { return c; }
>
> private:
> char c;
> };
>
> character(void) {}
> character(char value) : c(value) {}
>
> char value(void) const { return c; }
>
> bool operator_bool(void) const { return good(); }
>
> private:
> char c;
> };
>
> struct some_filter // details ommitted
> {
> template<typename Source>
> character::value_type get(Source& src)
> {
> character c;
> if (c = boost::io::get(src))
> {
> // c is good()
> };
> return c;
> }
> };

I'm not sure how this works; within some_filter get, do you have to use
c.value()?

> void user_func(void)
> {
> char c = get(some_source);
> }

> Obviously, this is getting further and further and from the original
> code, but only in terms of comprehension. The filter code itself
> remains transparent.

I'm going to try using char converion and a safe-bool conversion, except on
Borland where the safe-bool conversion will be a plain conversion. If it doesn't
work, I''ll go back to good().

Thanks for all your suggestions.

> Matt

Jonathan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk