Created on 2010-02-02.00:00:00 last changed 172 months ago
Proposed resolution:
Remove both variadic templates and initializer_list overloads of min, max, and minmax from the synopsis in [algorithms.general] and from [alg.min.max].
Note: This proposed resolution will resolve LWG 915 as NAD.
Rationale:
We prefer the solution of N2772 which will be reapplied.
[ 2010 Pittsburgh: Discussed and the LWG still prefers the initializer list solution of N2772. ]
In San Francisco, June 2008, N2722 was adopted, replacing the variadic templates min, max, and minmax by overloads that have an initializer_list<T> parameter. The paper showed benchmark results wherein initializer_list versions of min appeared to outperform the corresponding variadic template. Unfortunately, in October 2009 a very serious error was detected in the benchmark. (c++std-lib-25210). In fact, an initializer_list<T> version of min often appears to perform worse than the corresponding variadic template, especially when T has an expensive copy constructor (c++std-lib-25253, http://www.xs4all.nl/~nd/dekkerware/issues/n2772_fix).
IMO, the biggest problem of the initializer_list overloads is that they pass and return T objects by value. Which has the following consequences:
In the future, this problem might be solvable by using an initializer_list of const references, instead:
const T& min(initializer_list<const T&>); const T& max(initializer_list<const T&>); pair<const T&, const T&> minmax(initializer_list<const T&>);
It is unlikely that C++0x will support initializer_list<const T&>, but technically it seems possible to add such a language feature after C++0x (c++std-core-15428).
Variadic templates of min, max, and minmax, as proposed by N2551 (Sylvain Pion), do have some other advantages over initializer_list overloads:
Unfortunately, the variadic templates of min, max, and minmax may still need further improvement, before having them in the Standard Library. Especially the optional Compare parameter appears to be a concern. So for this moment I recommend to keep both versions out of C++0x, and postpone further discussion until after C++0x.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg1542 |
2010-10-21 18:28:33 | admin | set | messages: + msg1541 |
2010-10-21 18:28:33 | admin | set | messages: + msg1540 |
2010-02-02 00:00:00 | admin | create |