Thread: Utility of Function Objects

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008

    Well, I'll just drop some things here.

    If a compiler supports exceptions, at all, but doesn't ship with a `new' that throws an exception in the face of failure, you can always change that behavior directly all by yourself. The `new' operator is just an operator; it is an operator that calls `void * operator new (size_t)' which is only special in that it is the function that `new' calls by default. That said, if an exceptions capable compiler ships without a version of `new' that throws, it also probably doesn't have `std::bad_alloc' so you'll need to provide a definition for that as well.

    If a compiler doesn't support exceptions, then the questionable source has no meaning because it will not compile.

    If a compiler supports exceptions, but the exception mechanism is turned off the source will either not compile or fail to protect you at runtime because the throw will not be honored.

    A very picky compiler may, in the face of an `void * operator new (size_t)' implementation that doesn't throw an exception, inform you that such an implementation goes against the standard. This behavior is certainly not required.

    Because `void * operator new (size_t)' may be a user defined function linked by a third-party linker from third-party source a compiler will very likely never elide such an additional check and probably not issue a warning.

    So, if you feel you need to code in practice against a version of `new' that doesn't throw you only have two realistic options.


  2. #17
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Visual C++ 6.0 implementation of new was buggy anyways. The most notable being the fact that building against a user-defined new(std::nothrow) handler will be honored against the debug build and return null, but actually throw when linking against the release version of the runtime and turning on code optimization. I long forgot the actual implications of this mess but to my knowledge trying to fix new() for the benefit of VC++ 6.0 is a battle you can't win.

    If there is a reason to build against a compiler like VC++ 6.0, Yarin's code will not produce the results he's expecting. Although in practice that may not matter much...
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 12-04-2009, 05:24 PM
  2. vector of function objects
    By idleman in forum C++ Programming
    Replies: 6
    Last Post: 09-11-2009, 11:59 AM
  3. Replies: 11
    Last Post: 09-22-2006, 05:21 PM
  4. Replies: 4
    Last Post: 10-16-2003, 11:26 AM
  5. Can objects contain/return values like a function?
    By Panopticon in forum C++ Programming
    Replies: 3
    Last Post: 01-22-2003, 07:44 PM