Boost logo

Boost :

From: Matthew Vogt (mattvogt_at_[hidden])
Date: 2005-03-10 18:25:05


On Thu, 10 Mar 2005 15:36:40 -0700, "Jonathan Turkanis"
<technews_at_[hidden]> said:
> I just verified that Borland 5.6.4 complains of ambiguity when safe-bool
> and
> char conversions are combined. The same is true with a void* conversion
> instead
> of safe-bool. It works with a bool conversion instead of safe-bool, but
> this
> makes me a bit nervous. I'll have to wait until I have a bunch of filters
> implemented.

I realise this is getting out of hand, 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;
  }
};

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.

Matt

-- 
  Matthew Vogt
  mattvogt_at_[hidden]

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