Boost logo

Boost :

Subject: Re: [boost] Review Request : Boost.Range Extension
From: Akira Takahashi (faithandbrave_at_[hidden])
Date: 2012-06-07 23:46:07


2012/6/7 Michel Morin <mimomorin_at_[hidden]>:
> `as_container` looks interesting!

`as_container` is experimental feature. not include primary release.
(moved to experimental directory.)

I will add move_iterator version.

dest = src | as_moved_container;
( Container(make_move_iterator(begin(src), make_move_iterator(end(src)); )

> Here are some comments on `as_container`:
> * `as_container_functor` and `operator |` live in different name spaces.
> So ADL does not work.
>
> * `as_container` should live in boost::adaptors?

`as_container` is different other range adaptors.
`oven::copied` categorized to range algorithm, not range adaptor.

> * Built-in arrays are not supported by `as_container`.
>
> * Template conversion operator ambiguity:
> In C++03 and C++11, the following code
>    boost::array<int, 3> ar = {{1, 2, 3}};
>    std::vector<int> v(ar | as_container);
> fails to compile due to the ambiguity between
>  - `explicit vector(const allocator_type&)`,
>  - `vector(initializer_list<value_type>)`, and
>  - `vector(const vector&)`.
>
> In C++11, the following code
>    boost::array<int, 3> ar = {{1, 2, 3}};
>    std::vector<int> v;
>    v = ar | as_container;
> fails to compile due to the ambiguity between
>  - `vector& operator=(initializer_list<value_type>)`, and
>  - `vector& operator=(const vector&)`.
>
> One solution to this problem is applying SFINAE by "default template arguments
> for function templates" to the template conversion operator:
>    template <
>        class Container
>      , class Dummy1 = typename Container::difference_type
>      , class Dummy2 = typename Container::iterator
>    >
>    operator Container() const { /* ... */ }
> (`Dummy1` is used to SFINAE out `std::initializer_list` and `Dummy2` is
> used to SFINAE out `std::allocator`.)
> But this is a C++11 feature and so ambiguity with `std::allocator` is not
> solved in C++03. If there is no simple solution, simply documenting the
> limitation is an acceptable solution, I think.

Interesting.
I think better way is disable_if<!is_initializer_list<Container>>.
I will solve later.


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