c++0x

What's the future of std::valarray look like?

Up until fairly recently I hadn't been keeping up with the C++0x deliberations. As I try to become more familiar with it and the issues being worked, I came across this site which seems to be advocating for deprecating or removing std::valarray since most people are using Blitz++ instead. I guess I'm probably one of the few people out ...

Some clarification on rvalue references

First: where are std::move and std::forward defined? I know what they do, but I can't find proof that any standard header is required to include them. In gcc44 sometimes std::move is available, and sometimes its not, so a definitive include directive would be useful. When implementing move semantics, the source is presumably left in a...

How do I combine hash values in C++0x?

C++0x adds hash<...>(...). I could not find a hash_combine function though, as presented in boost. What is the cleanest way to implement something like this? Perhaps, using C++0x xor_combine? ...

C++0x without sequence point?

What does it mean by Sequence Point is deprecated from C++0x, Wikipedia says it is deprecated from C++0x. Does that mean undefined behaviors due to sequence point have no effect? ...

Using deprecated binders and C++0x lambdas

C++0x has deprecated the use of old binders such as bind1st and bind2nd in favor of generic std::bind. C++0x lambdas bind nicely with std::bind but they don't bind with classic bind1st and bind2nd because by default lambdas don't have nested typedefs such as argument_type, first_argument_type, second_argument_type, and result_type. So I...

About variadic templates

Hi, I'm currently experiencing with the new c++0x variadic templates, and it's quite fun, Although I have a question about the process of member instantiation. in this example, I'm trying to emulate the strongly typed enum with the possibility of choose a random valid strong enum (this is used for unit testing). #include<vector> #in...

forward/strong enum in VS2010

At http://blogs.msdn.com/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx there is a table showing C++0x features that are implemented in 2010 RC. Among them are listed forwarding enums and strongly typed enums but they are listed as "partial". The main text of the article says that this means they are eithe...

lambda traits inconsistency across C++0x compilers

I observed some inconsistency between two compilers (g++ 4.5, VS2010 RC) in the way they match lambdas with partial specializations of class templates. I was trying to implement something like boost::function_types for lambdas to extract type traits. Check this for more details. In g++ 4.5, the type of the operator() of a lambda appears...

Is this list-initialization of an array of unknown size valid in C++0x?

Is this list-initialization of an array of unknown size valid in C++0x? int main() { int x[]{0, 1,2,3,4}; return x[0]; } I believe it is valid, but would appreciate some confirmation. If anyone could quote from the C++0x-FCD to support their case, it would be greatly appreciated. Thanks! ...

How to properly use references with variadic templates

I have something like the following code: template<typename T1, typename T2, typename T3, typename T4> void inc(T1& t1, T2& t2, T3& t3, T4& t4) { ++t1; ++t2; ++t3; ++t4; } template<typename T1, typename T2, typename T3> void inc(T1& t1, T2& t2, T3& t3) { ++t1; ++t2; ++t3; } template<typename T1, typename T2> void inc...

Can a stack have an exception safe method for returning and removing the top element with move semantics?

In an answer to a question about std::stack::pop() I claimed that the reason pop does not return the value is for exception safety reason (what happens if the copy constructor throws). @Konrad commented that now with move semantics this is no longer relevant. Is this true? AFAIK, move constructors can throw, but perhaps with noexcept ...

Should I use C++0x Features Now?

With the official release of VS 2010, is it safe for me to start using the partially-implemented C++0x feature set in my new code? The features that are of interest to me right now are both implemented by VC++ 2010 and recent versions of GCC. These are the only two that I have to support. In terms of the "safety" mentioned in the first...

"long int", "long long" Data Types

Hi, What is the purpose of these new data types? I will normally just use an "int" or a "long" but why do these exist? What new function or purpose do they bring? ...

Range-based for statement definition redundancy

Looking at n3092, in §6.5.4 we find the equivalency for a range-based for loop. It then goes on to say what __begin and __end are equal to. It differentiates between arrays and other types, and I find this redundant (aka confusing). It says for arrays types that __begin and __end are what you expect: a pointer to the first and a pointer...

How do I simplify this templated vector initializer loop using lambdas or STL transform?

How do I simplify this templated vector initializer loop using lambdas or some kind of STL transform? template<typename T> template<typename... Args> void InitToRandomValues(vector<T>* retval, int n, RNG& rng, Args const&... args) { retval->resize(n); for (auto it = retval->begin(); it != retval->end(); ++it) { typename ...

How to enable nullptr from C++0x in the Visual C++ 2010?

I wonder how can I enable the nullptr in the just released Visual Studio 2010. (C++ project, not managed). This is one of the new features but it is not available by default and looking inside the documentation at http://msdn.microsoft.com/en-us/library/4ex65770(VS.100).aspx it seams that it is enabled by /clr but this is managed! Is t...

What is the purpose of using a reference to a reference in C++?

In my adventures studying the boost libraries, I've come across function signatures that have parameters which are a reference to a reference to an object. Example: void function(int && i); What is the purpose/benefit of doing it this way rather than simply taking a reference to an object? I assume there is one if it's in boost. ...

Why is shrink_to_fit non-binding?

The C++0x FCD states in 23.3.6.2 vector capacity: void shrink_to_fit(); Remarks: shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations. end note] What optimizations are intended to be allowed? ...

g++ and c++0x specification support

although it's been said that the support for c++0x new features in g++ are in experimental mode, many gcc developer claimed that you can use most of the new features in your codes and get the program to work. but when I try to compile this simple program it results in segmentation fault. Why? #include <thread> #include <iostream> void...

Undefined symbols for C++0x lambdas?

I was just poking around into some new stuff in C++0x, when I hit a stumbling block: #include <list> #include <cstdio> using namespace std; template <typename T,typename F> void ForEach (list<T> l, F f) { for (typename list<T>::iterator it=l.begin();it!=l.end();++it) f(*it); } int main() { int arr[] = {1,2,3,4,5,6}; ...