[PATCH] [libc++] Move enable_if to 2nd argument of std::vector(iterator, iterator) ctor

Howard Hinnant hhinnant at apple.com
Sat Sep 21 16:28:47 PDT 2013

On Sep 21, 2013, at 7:19 PM, Matt Calabrese <rivorus at gmail.com> wrote:

> On Sat, Sep 21, 2013 at 3:12 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> I don't believe this is a correct change.
>     std::vector<int> v( {}, my_weird_iterator );
> ... cannot deduce the type of `_InputIterator`.
> This is a prime candidate for my function-template-parameter-default enable_if approach. For details, see http://www.boost.org/doc/libs/1_54_0/libs/utility/enable_if.html#sec:enable_if_0x . By using this approach, you'd avoid any potential corner-case deduction issues, since the SFINAE happens as a part of forming the template parameter kind, separate from any function parameters themselves. The documentation linked is for boost::enable_if, but it will work perfectly fine with std::enable_if as well. If you use this approach, be sure that the enable_if is used when forming the template parameter kind as is shown in the documentation and not as a part of the default argument itself.

I think the reason I may not have chosen that initially is that it did not work in C++03.  However that code was written around 2007 and your suggestion may actually work in -std=c++03 today (haven't checked).


More information about the cfe-commits mailing list