|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2004-05-18 10:20:43
From: christopher diggins <cdiggins_at_[hidden]>
> From: "Rob Stewart" <stewart_at_[hidden]>
>
> > I don't understand mytype::get_constraints().max() to not always
> > be available. If I wanted that information, I'd write that
> > expression (instead of mytype::max()) and then be surprised when
> > it didn't work.
>
> When working with any parameterized type, it is natural to expect the return
> value of some functions to be of a type equal to a parameter. It is not
> natural to expect that the existance of methods to be conditional on the
> parameter.
It is natural to assume that a parameterizing type meets the
requirements of the template upon which it is used. If those
include supplying min() and max() functions, then there's no
surprise if things break when the parameterizing type fails to
meet its obligation.
> > It's simple enough to require that the template parameter supply
> > min() and max() so that derivation yields those functions in
> > mytype's interface. Then, it's a moot point whether min() and
> > max() are part of a static or non-static interface for mytype.
>
> The constrained_value type allows constraints which have nothing to do with
> min() and max() so requiring it in the parameter seems arbitrary.
I don't get it. Among the constraints are the minimum and
maximum values the type may assume, right? Why wouldn't min()
and max() be part of that interface?
> > > I don't see how the advantage of the shorthand justifies the case for
> > > parameter inheritance here.
> >
> > I don't see that you've solved any problem with your approach.
>
> I am simply tryign to use parameterized types in a more manner that is more
> widely understood and fits the natural assumptions of programmers.
The desire to "dumb down" the interface is good until it bumps
into other goals. Balance is the key. The question is what is
more obvious to end users. I contend, with Jeff, that c_v.max()
is more obvious and sensible than
c_v_type::get_constraints().max(). That c_v.max() imposes a
requirements on the parameterizing type, and that the
parameterizing type is used as a base class, is not critical in
my mind. The important thing is to document the requirements on
the parameterizing type and on the constrained_value class
template itself.
You might have mentioned it in one of your posts, but I didn't
see where the object returned by c_v_type::get_constraints()
would get its minimum and maximum values. Of what type is that
object? How was that type determined? (Note: I haven't looked
at your code, just your posts.) The answers to those questions
will be telling as to how much you've reduced what you perceive
to be cognitive complexity among the design alternatives.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk