Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-08-09 12:46:23

From: Florian Stegner <FlSt_at_[hidden]>
> Rob Stewart wrote:
> >From: FlSt_at_[hidden]
> >
> >"n_m_of" uses anti-alphabetical ordering of the letters. That
> >rather suggests the template argument order of maximum then
> >minimum. Perhaps changing to "x_y_of" or "a_z_of" would be
> >better?
> >
> Hmm... i,j,k are typical letters for indexes.. After that i_of and
> i_j_of are good choices.

Not all ranges are random access and we're not specifying two
indices. We're instead specifying a maximum and minimum count.

I rather liked the "subrange" or "subset" names that Matthew Vogt
suggested (though he later recanted his suggestion of
"subrange"). Unfortunately, those don't suggest the min/max
counts needed.

It occurs to me that most of these names are suggestive of
creating a subrange ("i_j_of" suggests the i'th through j'th
values in the range, for example) which then participates in the
comparison. That, of course, isn't what happens. Instead, we
need to indicate that between the minimum and maximum number of
elements, inclusive, satisfy the predicate.

As Matthew mentioned, the between(1, 2).items_of(a) spelling is
clear, but I find it rather long compared to subrange_of<1,2>(a)
or n_m_of<1,2>. Besides, we still need a name for the resulting
type that users might need to put in a variable.

In my library, there are these correspondences (Florian has a
different set of names):

   function class
   template template
   -------- ----------
   all_of all_values
   any_of any_value
   each_of each_value
   n_of n_values
   n_m_of n_m_values
   none_of no_values
   one_of one_value

Thus, you could write:

   typedef std::set<int> range_type;
   range_type r;
   // populate r;
   all_values<range_type> const all(all_of(r));

What about n_m_of?

   n_m_values<range_type> const some(between(3, 5).items_of(r));

I picked "some" as the variable name. Would "some_of" work?

   some_values<range_type> const some(some_of(3, 5, r));


   some_values<range_type> const some(between(3, 5).items_of(r));

"exactly" has also been suggested

   n_values<range_type> const n(exactly(3).items_of(r));

as an alternative to

   n_values<range_type> const n(n_of(3, r));

Should that actually return a "some_values?"

   some_values<range_type> const n(exactly(3).items_of(r));

If we use "some_values" do we need "n_of" or "n_m_of?" They're
shorter, but certainly not as clear. ("all," "none," and "one"
provide efficiency, so I plan to keep them.)

Rob Stewart                           stewart_at_[hidden]
Software Engineer           
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at, gregod at, cpdaniel at, john at