c++0x

G++ 4.5 Bug: No diagnostic for narrowing in initializer list

I tried the following code: int main() { int x {23.22}; } which includes an initialization that requires narrowing, but the code compiles fine without any error or warning. On the other hand, the following code gives error: int main() { int x[]{23.22}; } Have I found a bug or what? PS: I'm currently using GCC 4.5.0 ...

Problem by a reference variable of a template parameter

The following small example shows my problem: template<class T> struct X { static void xxx(T& x) { } static void xxx(T&& x) { } }; int main(int argc, char** argv) { int x = 9; X<int>::xxx(x); // OK. X<int&>::xxx(x); // ERROR! return 0; } Error message (GCC): error: ‘static void X::xxx(T&&) [with T = int&]’...

Will C++0x provide hashing functions for std::type_info?

Hello everyone :) I'm still working on a good solution to my One-Of-A-Type Container Problem -- and upon reflection I think it would be nice to be able to just use something like a std::map<std::type_info, boost::any>. Unfortunately, std::type_info does not define an operator<, and I think it'd be unreasonable for it to define one. How...

Can lambda functions be templated?

In c++0x is there a way to template a lambda function? Or is it inherently too specific to be templated? I understand that I can define a classic templated class/functor instead but the question is more like : does the language allow templating lambda functions? ...

Advantages of using forward

In perfect forwarding, std::forward is used to convert the named rvalue reference t1 and t2 to unnamed rvalue reference. What is the purpose of doing that? How would that effect the called function inner if we leave t1 & t2 as lvalue? template <typename T1, typename T2> void outer(T1&& t1, T2&& t2) { inner(std::forward<T1>(t1), std...

Optimizing away a "while(1);" in C++0x

I have heard and read that C++0x allows an compiler to print "Hello" for the following snippet #include <iostream> int main() { while(1) ; std::cout << "Hello" << std::endl; } It apparently has something to do with threads and optimization capabilities. It looks to me that this can surprise many people though. Does someone...

Modules in C++0x

Hi, I just discovered this old C++0x draft about modules in C++0x. The idea was to get out of the current .h/.cpp system by writing only .cpp files which would then generate module files during compilation, which would then in turn be used by the other .cpp files. This looks like a really great feature. But my question is: why did the...

What are rvalues, lvalues, xvalues, glvalues, and prvalues?

In C++03, an expression is either an rvalue or an lvalue. In C++0x, an expression can be an: rvalue lvalue xvalue glvalue prvalue Two categories have become five categories. What are these new categories of expressions? How do these new categories relate to the existing rvalue and lvalue categories? Are the rvalue and lvalu...

Delegate in C++0x

Hi! I want to ask, does C++0x going to provide delegate ? If no, tell me what is the best way (most efficient) to use delegation in C++ ? Boost.Signals ? FastDelegate ? Or something other? ...

tr1::unique_ptr and SelectObject()

Hi, I have some original code that manages exception safety like this: void foo() { HDC hdc = //get an HDC HBITMAP hbitmap = //get an HBITMAP HGDIOBJ hbitmapOld = SelectObject(hdc, hbitmap); try { //do something that may throw an exception } catch (...) { SelectObject(hdc, hbitmapOld); thro...

Count of parameters in a parameter pack? Is there a C++0x std lib function for this?

I was just wondering if there was anything in the C++0x std lib already available to count the number of parameters in a parameter pack? I'd like to get rid of the field_count in the code below. I know I can build my own counter, but it just seems like this would be an obvious thing to include in the C++0x std lib, and I wanted to be s...

Why is std::function not equality comparable?

This question also applies to boost::function and std::tr1::function. std::function is not equality comparable: #include <functional> void foo() { } int main() { std::function<void()> f(foo), g(foo); bool are_equal(f == g); // Error: f and g are not equality comparable } The operator== and operator!= overloads are declared ...

Variadic templates

Hi all, I have seen a lot of links introduced the variadic templates. But I have never seen one compilable example that demonstrates this approach? Could someone provides me some links in which such compilable examples can be found? regards Sami ...

Best way to initialize class's inherited member var of type std::array?

Entity has a member var of type std::array. Student inherits from Entity, and will need to initialize the std::array member var it inherited. Below is the code I'm using to do this, but it involves casting a brace-enclosed list to std::array. I'm not sure this is the correct or optimal way to do this. Using a brace-enclosed or double...

Instantiating template with a variably modified type

Hi, One of my class' member method take as an argument of enumeration type: it produces different side effects for different enum. I was wondering whether it's possible to use template as a lookup table, two possible solutions came up to my mind, but none of them seems to work: //// 1 //// class A { public: enum AEnum : uint...

address of c++ template function

Why does this fail to compile? (g++-4.5) template < typename U > static void h () { } int main () { auto p = &h<int>; // error: p has incomplete type } EDIT: Here is a work-around: template < typename U > static void h () { } int main () { typedef decltype (&h<int>) D; D p = &h<int>; // works } ...

new version of c++

is there gonna be a new version for c++ and when? ...

Handmade auto template (without using C++0x)

How can be realized the auto keyword functionality without using c++0x standard? for(std::deque<std::pair<int, int> >::iterator it = points.begin(); it != points.end(); ++it) { ... } Maybe such class: class AUTO { public: template <typename T1> AUTO(T1); template <typename T2> operator T2(); }; With such usage: ...

How to specify c++0x flag on cent os

The command g++ -o myprogram myprogram.c -std=c++0x works well on ubuntu but when I try the same with centos it throws me an error cc1plus: error: unrecognized command line option "-std=c++0x". Even google doesn't give the answer. Have anybody experienced it before? Does anybody know the solution? ...

read arguments from variadic template

Hi all, I am a little confused about how can I read each argument from the tuple by using variadic templates. Consider this function: template<class...A> int func(A...args){ int size = sizeof...(A); .... } I call it from the main file like: func(1,10,100,1000); Now, I don't know how I have to extend the body of func to be able to...