Coder Social home page Coder Social logo

Add support for string view? about pprintpp HOT 3 CLOSED

tfc avatar tfc commented on June 12, 2024 1
Add support for string view?

from pprintpp.

Comments (3)

tfc avatar tfc commented on June 12, 2024

Hi,

this seems possible to me. A way to implement this would be to upgrade the part of the algorithm to be able to look at the next two types instead of only one, and pop them both off if there is a size_t and a char* coming.
For implementation mechanics, this means that at this code line we could feed the list of the remaining types to the format_str function, so it can consume as many as it wants. Then, it could return the rest of the list. Looking at this, my gut feel says that we would not need to change much around that.

I would however certainly not implement this like in your example where writing {} suffices, because i think it is too dangerous to have just the order of a size_t and a char* types in the arguments and then imply "so this must be a string view".
In that scenario i would at least have some kind of {sv} so the user can express "yes the following size_t and char* values are really from a string view and you can use them like that", similar as we already do that for string pointers where the user has to write {s}.

What do you think?

from pprintpp.

thealastair avatar thealastair commented on June 12, 2024

I was hoping there would be a way to not have to provide the size and data pointer directly, rather just the string view itself
have this library add the argument, but I guess that's not possible? The {sv} option would definitely be useful.

from pprintpp.

tfc avatar tfc commented on June 12, 2024

Oh right, i missed that detail of your example.

It is possible, but then we'd be creating custom code again (Just like the template-based printf function in Bjarne's original C++ book).
The point of pprintpp is that it only creates the format string and leaves the rest of the printf call as is, resulting in zero extra code per printf call.

It seems like libfmt is what you need.

from pprintpp.

Related Issues (15)

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.