Giter Site home page Giter Site logo

Comments (5)

pdimov avatar pdimov commented on May 29, 2024

You can forward-declare result_for. See for example how it's done in Variant2: https://github.com/boostorg/variant2/blob/9e4234bfd5688c0272b641954ab2f23f8ce9c613/include/boost/variant2/variant.hpp#L2430-L2530

from json.

panic-sell avatar panic-sell commented on May 29, 2024

Thanks. IIUC, by forward declaring all Boost.Json names and only implementing tag_invoke() in terms of those forward declarations, we can avoid making our custom types depend on Boost.Json

That said, I notice examples in https://www.boost.org/doc/libs/1_83_0/libs/json/doc/html/json/conversion/non_throwing_conversions.html use result_for (despite depending on Boost.Json per calls to jv.get_array()). Is the recommendation to prefer result_for over result even when code does depend on Boost.Json? If so, why?

from json.

pdimov avatar pdimov commented on May 29, 2024

The same example does use result directly inside the function; result_for in the signature is probably only used to match the declaration of tag_invoke given above.

I can't think of any reason to prefer result_for if you don't mind including JSON (or System) headers.

from json.

grisumbras avatar grisumbras commented on May 29, 2024

Yes, there's absolutely no reason to prefer result_for over result If you're including JSON headers. As @pdimov suggested, the linked example uses result_for in the return type to match the signature, in order to be less confusing for the user.

from json.

panic-sell avatar panic-sell commented on May 29, 2024

Awesome, thanks for the explanation.

from json.

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.