Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-03-10 02:20:07


--- In boost_at_y..., Howard Hinnant <hinnant_at_t...> wrote:
> A typical implementation might look something like (warning,
unchecked
> pseudo code):
>
> template <class F>
> vector(size_type n, F init, const Allocator& a = Allocator())
> {
> choose_F_init(n, init, a, int2type<!is_convertible<F,
> value_type>::value>());
> }
>
> Then you've got two overloads for choose_F_init:
>
> 1. Takes a int2type<false>. F *is* convertible to value_type.
This is
> a mistaken binding. Redirect to the code that implements
> vector(size_type, value_type, allocator); (converting init to a
> value_type of course).
>
> 2. Takes a int2type<true>. F will not convert to value_type.
This is
> the real deal, do whatever you were going to do in the first place
with
> (n, init, a).

Thanks a lot for this!

> Now isn't:
>
> template <class F : !is_convertible<F, value_type>::value>
> vector(size_type n, F init, const Allocator& = Allocator());
>
> *much* easier?! :-) The compiler does the redirecting for you, but
> under your precise instructions.

I am 100% with you. Remember the thread starting with message 23337?
Ralf


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