Code Monkey home page Code Monkey logo

Comments (10)

zajo avatar zajo commented on August 29, 2024

This is a very old library from before we had move. What is the concern with the copy? Presumably we're using this just before we throw, so any concerns about speed are probably not warranted. Also, if you pass an unnamed temporary to enable_error_info, the copy constructor is elided.

from exception.

zlojvavan avatar zlojvavan commented on August 29, 2024

just the fact that there's unnecessary copy operation that probably could be avoided even without move semantics if that's what you meant

well, yes I used it before uniformly but figured it does unnecessary copy so I've had to separate my throw helper in two distinct ones

template <typename T> [[noreturn]] std::enable_if_t< std::is_base_of_v<boost::exception, T>> ThrowExceptionImpl(T const& be, char const* current_function, char const* file, int line) { ProcessErrorInfoContainer(be); ... } template <typename T> [[noreturn]] std::enable_if_t< !std::is_base_of_v<boost::exception, T> > ThrowExceptionImpl(T const& e, char const* current_function, char const* file, int line) { ThrowExceptionImpl(boost::enable_error_info(e), current_function, file, line); }

thought you would be interested to optimize it away without relying upon copy elision

from exception.

zajo avatar zajo commented on August 29, 2024

What is the concern, the the size of the generated code or the speed?

from exception.

zlojvavan avatar zlojvavan commented on August 29, 2024
  1. the fact there's unnecessary copy operation is enough for me
  2. I'm not so sure about "if you pass an unnamed temporary to enable_error_info, the copy constructor is elided", see https://godbolt.org/z/vvdj9ooY3

according to Explanation
"1) First, copy-initializes the exception object from expression" and though there's also "The copy/move (since C++11) may be subject to copy elision" part and my example might be wrong IIRC in my experience I observed copy operation

p.s. despite being "old" I find that lib very useful and wish all boost libs used boost::exception/throw_exception and boost/std offered customization points for throwing exceptions (as already asked in #25 (comment)) as some environments such as codegear/embarcadero allow

from exception.

zajo avatar zajo commented on August 29, 2024

I also checked whether the copy elision happens, but it doesn't because it turns out std::~exception is defined out of line. Actually if you use boost::throw_exception there is no problem right? It's got its own mechanism for injecting boost::exception as a base.

from exception.

zlojvavan avatar zlojvavan commented on August 29, 2024

so apparently I was right that copy elision on throw is wishful thinking
and boost::throw_exception(derived_exception()) still invokes copy constructor and increments the counter

from exception.

zajo avatar zajo commented on August 29, 2024

Anyway, I don't see a practical problem with any of this.

Have you considered using Boost LEAF instead? It is a better solution to the same problem, assuming its limitations are not an issue for your use case.

from exception.

zlojvavan avatar zlojvavan commented on August 29, 2024

well of course it's up to you whether to fix it or not, though probably cost of copying exception in some derived hierarchies might be not so low. at least I think I did my best to highlight the problem

I believe I considered LEAF couple of years ago and while I find it really interesting and will probably start using it in new projects some day I guess it cannot replace current infrastructure (including boost/exception) in existing projects/libs

from exception.

zajo avatar zajo commented on August 29, 2024

I prefer to not make unnecessary changes to Boost Exception, as I can not test with old MSVC versions.

Here is guide on how to migrate from Boost Exception to LEAF, it's straight forward.

Also, you can handle Boost Exception error info with LEAF.

from exception.

zlojvavan avatar zlojvavan commented on August 29, 2024

even if it's "straight forward" atm there's no motivation and sometimes technical feasibility to refactor all existing sources to migrate to LEAF

from exception.

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.