boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
101 stars 113 forks source link

boost.vector doesn't work with common_iterator. #207

Closed nanoric closed 2 years ago

nanoric commented 2 years ago

Check the code blow:

#include <type_traits>
#include <boost/container/vector.hpp>
#include <iterator>
#include <vector>
#include <ranges>

int main(){
    using Ints = std::vector<int>;
    Ints ints = {1,2,3};

    using I = std::counted_iterator<Ints::iterator>;
    using S = std::default_sentinel_t;
    using C = std::common_iterator<I, S>;

#define ARGS C(std::counted_iterator(ints.begin(), ints.size()-1)), \
          C(std::default_sentinel)
    std::vector(ARGS);
    // these should work, but not because of different errors.
    //boost::container::vector<int>(ARGS);
    //boost::container::vector(ARGS);
}
igaztanaga commented 2 years ago

Thanks for the report. Which compiler and version are you using?

nanoric commented 2 years ago

I'm using Visual Studio 2022 17.0.4. And maybe you can check with online compiler: godbolt

igaztanaga commented 2 years ago

Thanks for the report. Boost.Container uses a simplified iterator_traits model to avoid costly include overhead, but C++20's new requirements for iterator_traits seem too complicated, so it's better to switch to std in those cases. I've committed a change (https://github.com/boostorg/move/commit/208df9f3c338674697614c125b4d98d9cc446173) in Boost.Move, which serves this iterator_traits emulation to Boost.Move and Boost.Intrusive and I'll complete it with a commit in Boost.Container.

nanoric commented 2 years ago

nice description and nice work.