Code Monkey home page Code Monkey logo

Comments (3)

Lastique avatar Lastique commented on August 15, 2024

Given the feedback in boostorg/core#113, I kind of agree that the second constructor is probably a bad idea. The first one requires a modern standard library as it must only compile for contiguous iterators, which is C++20 I think. We currently don't have the infrastructure for this. I don't find the third one very useful, but fine, I guess.

from utility.

sehe avatar sehe commented on August 15, 2024

I agree on the third one.

Let's accept this as not desirable for now. In reality, the purpose of string_view alternatives outside the standard library are either supporting older compilers (so the missing c++20+ constructors are moot) or adding interoperability benefits (e.g. core::string_view).

from utility.

GielVanSchijndel-TomTom avatar GielVanSchijndel-TomTom commented on August 15, 2024

What about adding a more restricted version of the first constructor?

explicit constexpr basic_string_view(const_iterator first, const_iterator last);

This would at least provide compatibility with iterator_range's copy_range and as a result make string_view usable with string algorithms without needing to do a follow up conversion. Take for example this reduced example taken from code we're actually using (where we're forced to have an intermediate std::vector<boost::iterator_range<const char*>> to convert from):

auto do_split(boost::string_view str) {
    std::vector<boost::string_view> tokens;
    boost::split(tokens, str, [](const char c) { return c == ','; });
    return tokens;
}

This would seemingly provide partial forward compatibility with C++20's constructor without creating backwards compatibility problems in the future (that I can see).

Edit: I added this as a comment on boostorg/core#113 (comment). But I was unaware that's a different string_view than this one.

from utility.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.