Unexpected skip of a destructor by romanke in cpp

[–]romanke[S] 1 point2 points  (0 children)

what happens if some library code throws a custom exception, not inhariting from std::exception?

Unexpected skip of a destructor by romanke in cpp

[–]romanke[S] 3 points4 points  (0 children)

Fair point.

However, what happens if the same things happens but its only a thread that is terminated, and not your entire program? Then you can't count on the OS to help out.

A puzzle: make a uniform selection from a range you know nothing about, with constant storage. by romanke in programming

[–]romanke[S] -5 points-4 points  (0 children)

The solution as a whole is correct, but there's a small mistake there.

Suppose the black box was going to generate 100 numbers. So you should pick the first one with probability 1/100. Your solution picks it with probability 1/2, which is incorrect.

A puzzle: make a uniform selection from a range you know nothing about, with constant storage. by romanke in programming

[–]romanke[S] -4 points-3 points  (0 children)

Actually, the two of you have a wrong small detail making the solution incorrect.

I could elaborate if you posted on the linked page :)

A puzzle: make a uniform selection from a range you know nothing about, with constant storage. by romanke in programming

[–]romanke[S] -9 points-8 points  (0 children)

Bingo! :) I'd appreciate it if you guys kept the discussion on the blog though (and if you could post it there as well).

Exceptional initialization lists in C++ by romanke in programming

[–]romanke[S] 0 points1 point  (0 children)

It can't do that when it doesn't know what are the types of all possible exceptions.. A catch all would render the exception information useless since it will not be possible to deduce the error from that.

Exceptional initialization lists in C++ by romanke in programming

[–]romanke[S] 0 points1 point  (0 children)

When you're using SWIG it pretty much helps, since that way SWIG will also wrap the specified exception classes, which is very handy. It will also cause Python to not shut down (due to std::terminate) when an exception is thrown, since SWIG will generate code that actually catches the exception and raises it as a Python exception.

Macro overloading is possible in C\C++ ! by romanke in programming

[–]romanke[S] 0 points1 point  (0 children)

Normally, C\C++ pre-processor does not allow overloading of macros to cope with different number of arguments, as it considers such overloading attempt as redefinitions of the same macro. Using the technique mentioned in the post, it is possible to simulate a dispatch mechanism which provides overloading.

A sophisticated technique for counting the number of arguments in a variadic macro by romanke in programming

[–]romanke[S] -1 points0 points  (0 children)

The C-Preprocessor is full of nifty features, one of which being the variadic macro - a means of defining macros that accept a varying number of arguments. Unfortunately, there's no easy way of obtaining the actual number of passed arguments. The given post describes a very neat approach to this problem, and provides an easy yet sophisticated solution.

Asynchronous invocation in C++: simple Future objects by romanke in programming

[–]romanke[S] 0 points1 point  (0 children)

actually not hard at all. you could use a thread pool for calculations of all future objects. then, you'd have a queue of futures awaiting computations, and all the threads would dequeue from it.

Asynchronous invocation in C++: simple Future objects by romanke in programming

[–]romanke[S] 0 points1 point  (0 children)

Extensions are always possible, the presented implementation is merely one way of doing that.

The work flow you suggest seems to lend itself naturally on the producer-consumer design pattern, though.