Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-10-10 14:31:41


On Wed, 9 Oct 2002, Thorsten Ottosen wrote:

> Peter Dimov <pdimov_at_[hidden]> wrote:
> > Why do you need so many headers?
>
> apparently I don't.

I'd be in favor of a naming format that was "init_map.hpp" for specific
code necessary for anything <map> and "init_list.hpp" for that code
necessary for anything in <list>. I'd not be in favor of including <list>
or <map> in those headers as I don't think these headers should be
included "in place" of the standard headers, but rather, in addition to
the standard headers. As such, not including the headers, is as if you
are making a basic assumption that the user did include them. This forces
the user to include them on his own, which is probably what he wants, if
he knows he's going to initialize a std::map or whatever.

> > init(container)(value1)(value2)(value3);
> >
> > or
> >
> > init(map)(key1, value1)(key2, value2);
>
> nice stuff! It is considerably simpler than my initial code. I presume you
> like the lisp syntax better :-)? As you know, I don't think it is the right
> one. One could choose
> to support both, though. The problem of missing a value in the assignment to
> the map is hypothetical. If I wan't to map int to int, I can make the
> mapping just as clear by using newline or tabs:
>
> set_map( m ) += 1,2 2,3 3,4 5,6;
> set_map( m ) += 1,2
> 2,3
> 3,4;
>

Given that you yourself did not do well in giving an example of
separation with whitespace, I think this speaks strongly for a pair-wise
syntax. In any case, I'm against something like assign_map(m) += or
append_map(m) =. Does the first do a clear() before it assigns? Does the
second? The "set_map" or "append_map" or "assign_map" suggests one way,
the "+=" or "=" suggests another. This ambiguity does not occur with the
parenthesis form, as there is no way to specify "multiple" meanings. This
double meaning problem is also what led me to propose doing away with the
name altogether and having: m += 1,2, 2,3, 3,4, 5,6;

I had considered a form such as m += 1, 2 + 3, 4 + 5, 6; but
unfortunately, the C++ syntax is to translate this to m += 1, 5, 9, 6; In
fact, there is no operator you could use that I can see.

The parenthesis form is not that hard. Add a space between the values and
the parenthesis, and the value isn't buried:

init(m)( 1, 2 )( 2, 3 )( 3, 4 );

In this case white space does enhance readability, but the syntax
guarantees the user won't make a mistake. In your case, whitespace might
add something, but the user can still make a mistake. Even something
like:

set_map(m) += 1,2, 2,3, 3,4, 5,6, 7,8, | 9,
              9,10, 11,12, 13,14, 15,16 17,18
              19,20;

With the user screen margin occuring where the | passes is possible. In
this case, white space doesn't save him from this mistake. And it could
be hard to find.

And I'm not in favor of naming anything that resides in the global
namespace "_".

> The first version is the best. One would never miss a value that way and the
> values are easier to read than something burried in paranthesis:
>
> init( m )(1,2)(2,3)(3,4);
>
> Now, your templates are really clever. I think that approach would remove
> much dependency. However, I think I will still get problems
> when I need to use set and stack because insert() is different for set and
> stack uses push(). What would be the most elegant way out of this trouple?

A second level of templates that partially specializes the
insertion/clearing functions based on the container passed could work...


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