c++0x

Why is C++0x's `noexcept` checked dynamically?

I am curious about the rationale behind noexcept in the C++0x FCD. throw(X) was depreciated, but noexcept seems to do the same thing. Is there a reason that noexcept isn't checked at compile time? It seems that it would be better if these functions were checked statically that they only called throwing functions within a try block. ...

decltype, result_of, or typeof?

I have: class A { public: B toCPD() const; And: template<typename T> class Ev { public: typedef result_of(T::toCPD()) D; After instantiating Ev<A>, the compiler says: meta.h:12: error: 'T::toCPD' is not a type neither decltype nor typeof work either. ...

Splitting a double vector into equal parts

Greetings, Any input on a way to divide a std::vector into two equal parts ? I need to find the smallest possible difference between |part1 - part2|. This is how I'm doing it now, but from what you can probably tell it will yield a non-optimal split in some cases. auto mid = std::find_if(prim, ultim, [&](double temp) -> bool { if(...

What elegant method callback design should be used ?

Hi, I'm surprised this question wasn't asked before on SO (well, at least I couldn't find it). Have you ever designed a method-callback pattern (something like a "pointer" to a class method) in C++ and, if so, how did you do it ? I know a method is just a regular function with some hidden this parameter to serve as a context and I hav...

How to find the length of a parameter pack ?

Hi All, Suppose I have a variadic template function like template<typename... Args> unsigned length(Args... args); How do I find the length of the parameter list using the length function ? ...

Why is there a sizeof... operator in C++0x?

I saw that @GMan implemented a version of sizeof... for variadic templates which (as far as I can tell) is equivalent to the built in sizeof.... Doesn't this go against the second design principle: prefer libraries to language extensions? ...

C++0x thread interruption

According to the C++0x final draft, there's no way to request a thread to terminate. That said, if required we need to implement a do-it-yourself solution. On the other hand boost::thread provides a mechanism to interrupt a thread in a safe manner. In your opinion, what's the best solution? Designing your own cooperative 'interruption...

initializer_list not working in VC10

hi i wrote this program in VC++ 2010: class class1 { public: class1 (initializer_list<int> a){}; int foo; float Bar; }; void main() { class1 c = {2,3}; getchar(); } but i get this errors when i compile project: Error 1 error C2552: 'c' : non-aggregates cannot be initialized with initializer list c:\users\pswin\documents...

Detect template presence at compilation time

GCC up to 4.5 doesn't have standard C++0x type trait template has_nothrow_move_constructor. I could use it in my package for optimization, but I don't want to rule out one of the common compilers and don't want to overload configuration with symbols like HAVE_STD_HAS_NOTHROW_MOVE_CONSTRUCTOR. Is it somehow possible to use that template...

How would one call std::forward on all arguments in a variadic function?

I was just writing a generic object factory and using the boost preprocessor meta-library to make a variadic template (using 2010 and it doesn't support them). My function uses rval references and std::forward to do perfect forwarding and it got me thinking...when C++0X comes out and I had a standard compiler I would do this with real v...

Correct use of boost lambda

Consider the following piece of C++0x code: a_signal.connect([](int i) { if(boost::any_cast<std::string>(_buffer[i]) == "foo") { base_class<>* an_object = new derived_class(); an_object->a_method(_buffer[i]); }}); How would it correctly look in Boost Lambda (since this C++0x feature can't be used in GCC 4.4 yet)? ...

GCC ICE -- alternative function syntax, variadic templates and tuples

(Related to C++0x, How do I expand a tuple into variadic template function arguments?.) The following code (see below) is taken from this discussion. The objective is to apply a function to a tuple. I simplified the template parameters and modified the code to allow for a return value of generic type. While the original code compiles...

C++0x lambda capture by value always const?

Is there any way to capture by value, and make the captured value non-const? I have a library functor that I would like to capture & call a method that is non-const but should be. The following doesn't compile but making foo::operator() const fixes it. struct foo { bool operator () ( const bool & a ) { return a; } }; int _...

Overload on reference, versus sole pass-by-value + std::move?

It seems the main advice concerning C++0x's rvalues is to add move constructors and move operators to your classes, until compilers default-implement them. But waiting is a losing strategy if you use VC10, because automatic generation probably won't be here until VC10 SP1, or in worst case, VC11. Likely, the wait for this will be measur...

What C++0x feature will have the most impact?

What will day to day C++ development be like in a few years? What C++0x features will change C++ development the most? In what order should I concentrate learning these new features? ...

How to interrupt a waiting C++0x thread?

I'm considering to use C++0x threads in my application instead of Boost threads. However, I'm not sure how to reimplement what I have with standard C++0x threads since they don't seem to have an interrupt() method. My current setup is: a master thread that manages work; several worker threads that carry out master's commands. Worke...

Goal of C's "auto" keyword

What is the goal of the "auto" keyword in C? With C++ 0x it got new meaning but does it mean that my code will break if I port C code over to a C++ 0x compiler? ...

Is `auto int i` valid C++0x?

In answering this question the question arose as to whether the traditional C meaning of the keyword auto (automatic storage) is still valid in C++0x now that it means type deduction. I remember that the old meaning of auto should remain where relevant but others disagreed. auto char c = 42; // either compilation error or c = '*' Lo...

Fill container with template parameters

I want to fill the template parameters passed to a variadic template into an array with fixed length. For that purpose I wrote the following helper function templates template<typename ForwardIterator, typename T> void fill(ForwardIterator i) { } template<typename ForwardIterator, typename T, T head, T... tail> void fill(ForwardIterato...

Using an initializer_list on a map of vectors

I've been trying to initialize a map of <ints, vector<ints> > using the new 0X standard, but I cannot seem to get the syntax correct. I'd like to make a map with a single entry with key:value = 1:<3,4> #include <initializer_list> #include <map> #include <vector> using namespace std; map<int, vector<int> > A = {1,{3,4}}; .... It dies...