Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2004-11-23 01:10:52


> Gennadiy Rozental wrote:
> >>You can't implement the same compile-time logic with less keystrokes.
> >>It's less capable because our design has a capability that yours
> >>doesn't. Not a matter of opinion, just a fact.
> >
> >
> > The only fact here is that you are making that statement. Let's take you
> > "more-capable" interface and implement solution for simple problem. Let
then
> > take my interface and implement the solution for the same problem using
my
> > "less-capable" interface. Let than compare which variant is easier and
> > shorter. And that would be *the fact* (it's still matter of
> > taste/preference, but I hope we will be able to see it clearly). Until
that
> > time you statement:
> >
> > "You can't implement the same compile-time logic with less keystrokes"
> >
> > *is* a matter of opinion and not a fact.
>
> Fair enough. So, please show us your code

I already did presented my solution to the problem I think Dave had in mind.
Authors on the other hand for some reason have difficulties backing up their
statements with any examples, even pseudocode.

> that "implement the same logic as with even less keystrokes"

I *never* told that my solution will use less keystrokes. Maybe less maybe
more. That is not the point.

> But please remember: less keystrokes doesn't mean better code.

Exactly my point.

 Ok. Here is how I understand the problem and how would solutions look like
(be aware of my not that perfect understanding of submitted library):

Problem implement function with 2 named parameter interface where parameter
'value' is not fixed type but should comply to compile time predicate
is_movable and parameter name is string:

Submitted library solution:
------------------------------

  keyword<struct name_t> name;
  keyword<struct value_t> value;

  struct f_keywords : keywords<
             named_param<
                name_t
              , boost::mpl::false_
              , boost::is_convertible<boost::mpl::_, std::string>
>
          , named_param<
                value_t
              , boost::mpl::false_
              , is_movable<boost::mpl::_>
>
>
  {};

  template<typename MovableType>
  void f_impl(std::string name, MovableType v )
  {
   ...
  }

  template<class Params>
  void f(Params const& p, typename f_keywords::restrict<Params>::type =
f_keywords())
  // I am not actually quite sure whether above is a proper way to enforce a
restriction
  {
      f_impl( p[name], p[value]);
  }

My suggested solution
------------------------------------

typed_keyword<std::string,struct name_t> name;
keyword<struct name_t> value;

template<typename MovableType>
typename boost::enable_if<is_movable<MovableType>, void>::type
f_impl(std::string name, MovableType v )
{
 ...
}

template<class Params>
void f(Params const& p)
{
   f_impl( p[name], p[value]);
}

------------------------------------

Now let's hear peoples subjective opinions on above choice. My position that
library should only provide support for strict type checking. Any other
"more flexible" restrictions are user responsibility (if necessary).

> Regards,
> --
> Joel de Guzman

Gennadiy


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