A question about threads in C/C++...
C++0x syntax
#include <thread>
void dummy() {}
int main(int, char*[]) {
std::thread x(dummy);
std::thread y(dummy);
...
return 0;
}
How many threads are there? Two (x and y) or three (x, y and main)? Can I call this_thread::yield() in main? And what do I get from calling this_thread:...
Working on this question, I found an inconsistent behavior.
Why reference binding behave different in a constructor from a common function?
struct A {
};
struct B : public A {
B(){}
private:
B(const B&);
};
void f( const B& b ) {}
int main() {
A a( B() ); // works
A const & a2 = B(); // C++0x: works, C++03: fails
f( B() ...
Let's say I have a function:
typedef std::vector<int> VecType;
VecType randomVector();
int processing()
{
VecType v = randomVector();
return std::accumulate(v.begin(), v.end(), 0);
}
Does C++0x specifically say the spurious copy will be averted from the return value of randomVector? Or would a compiler need to implement the R...
Please, excuse my ignorance about this subject :)
C++0x is introducing unordered_set which is available in boost and many other places. What I understand is that unordered_set is hash table with O(1) lookup complexity. On the other hand, set is nothing but a tree with log(n) lookup complexity. Why on earth would anyone use set instead o...
Concepts didn't make the C++0x standard, but Boost still provides The Boost Concept Check Library (BCCL). I guess that BCCL doesn't cover everything that was meant to into the C++0x standard. What is the difference between BCCL and the proposed C++0x solution?
...
In an effort to avoid the C-Pound mistake, I'm curious as to how C++0x is pronounced.
The first part is pretty easy (see plus plus), but is the next part "zero ex", "oh ex", "ox", etc?
...
Is anyone using the GCC 4.4.0 C++0x support in production? I'm thinking about using it with the latest MinGW, but I'm not sure if it's mature enough.
I'm interested in:
TR1 support
auto
initializer lists
...
In the following example (Chapter 2), Anthony Williams is trying to parallelize the standard accumulate function. my question is why is he doing this:
unsigned long const max_threads=(length+min_per_thread-1)/min_per_thread;
why add length and subtract 1?
why not just:
unsigned long const max_threads=length/min_per_thread;
....
At some point I remember reading that threads can't be safely created until the first line of main(), because compilers insert special code to make threading work that runs during static initialization time. So if you have a global object that creates a thread on construction, your program may crash. But now I can't find the original art...
For instance why does most members in STL implementation have M or _ or __ prefix?
Why there is so much boilerplate code ?
What features C++ is lacking that would allow make vector (for instance) implementation clear and more concise?
...
I have tried to find some information on D. I do especially like this comparison with C++ to get an overview on what it is.
Now I am asking myself: how often D is used in the field, and how much of a viable alternative is it to C++?
...
I'm trying to typedef either an unordered_map or std::map depending whether there are TR1 libraries available. But I don't want to specify the template parameters. From what i've read so far, typedef'ing templates without arguments is not possible until official c++0x standard is available. So does anyone know an elegant workaround for t...
I've been reading a bit about lambda expressions on the internet recently and it seems to me that C++0x's lambda expressions will not have a single type (or types) that will bind exclusively to lambda expressions -- in other words, lambda expressions will only match template arguments or auto arguments/variables. What happens, as describ...
Hello all,
I've written a handful of basic 2D shooter games, and they work great, as far as they go. To build upon my programming knowledge, I've decided that I would like to extend my game using a simple scripting language to control some objects. The purpose is more about the general process of design of writing a script parser / exec...
I remember seing something like this being done:
template <ListOfTypenames>
class X : public ListOfTypenames {};
that is, X inherits from a variable length list of typenames passed as the template arguments. This code is hypothetical, of course.
I can't find any reference for this, though. Is it possible? Is it C++0x?
...
The boost library, and it seems the upcoming C++0x standard, define various type trait templates to differentiate between objects which have trivial constructors, copy constructors, assignment, or destructors, versus objects which don't. One of the most significant uses of this is to optimize algorithms for certain types, e.g. by using ...
Is there any portable way to determine what the maximum possible alignment for any type is?
For example on x86, SSE instructions require 16-byte alignment, but as far as I'm aware, no instructions require more than that, so any type can be safely stored into a 16-byte aligned buffer.
I need to create a buffer (such as a char array) wh...
Consider a class of which copies need to be made. The vast majority of the data elements in the copy must strictly reflect the original, however there are select few elements whose state is not to be preserved and need to be reinitialized.
Is it bad form to call a default assignment operator from the copy constructor?
The default assi...
The more I work with C++ locale facets, more I understand --- they are broken.
std::time_get -- is not symmetric with std::time_put (as it in C strftime/strptime) and does not allow easy parsing of times with AM/PM marks.
I descovered recently that simple number formatting may produce illegal UTF-8 under certain locales (like ru_RU.UTF...
A common question that comes up from time to time in the world of C++ programming is compile-time determination of endianness. Usually this is done with barely portable #ifdefs. But does the C++0x constexpr keyword along with template specialization offer us a better solution to this?
Would it be legal C++0x to do something like:
con...