Fwd: Re: [Patch] Remove workaround for copy_backward

Gabriel Dos Reis gdr@integrable-solutions.net
Mon Sep 29 07:00:00 GMT 2003


Douglas Gregor <gregod@cs.rpi.edu> writes:

| On Sunday 28 September 2003 03:32 pm, Gabriel Dos Reis wrote:
| >   (3) breaks conforming codes (even if we may disagree on their being
| >       good practice)
| >
| >      I'd take my favorite example, page 9 from
| > http://www.cmla.ens-cachan.fr/~dosreis/C++/talks/generic-programming-in-cxx
| >.pdf
| >
| >      #include <vector>
| >      struct X {
| >         explicit X(int) { }
| >      };
| >
| >      int main()
| >      {
| >         std::vector<X> w(25, 4);                // OK
| >      }
| >
| >     With enable-if work-around as proposed, the above will be
| >     (incorrectly) rejected. If you think it is contrived example (and
| >     I conceide the point), think
| >
| >       std::vector<std::vector<int> > matrix(3, 3);
| >
| >     I've already seen codes like that.
| >
| > -- Gaby
| 
| This is the killer argument, then, against using the enable-if workaround. I 
| suppose (but can't confirm) that the fact that the above works was an 
| unintended consequence of the use of static_cast<> in the
| specification. 

I've raised that point several times in discussions with many LWG
members; while they seem to agree that the above was not intented,
they also think that it has some virtues... For example, the above
does a direct construction, instead of copy-construction, of the
matrix rows/columns.

| Have you submitted a DR on this? If not, should someone do so? 

I did not submit a DR, because I don't how to argue for breaking codes
in order to correct our own failure of appreciating templates :-)
If you think it worths a DR, please submit one; we'll see what the
whole LWG thinks. 

-- Gaby



More information about the Libstdc++ mailing list