c++0x

How to compile and run C++0x with GCC/G++ in Eclipse CDT?

I am trying to figure out how to use the upcoming C++ release 0x. It should be available in GCC 4.3+ with using the gcc std=gnu++0x option. My simple thread program using 0x compiles in Eclipse CDT with std=gnu++0x added in Project > properties > C/C++ Build > Settings > Miscellaneous > Other flags. #include <iostream> #include <thread...

What to do with template typenames for optional arguments?

First of all, the code: template<typename Func, typename Func2> void ForEachField(Func normalHandler, Func2 arrayHandler = NULL, bool skipUnknowns = true) { for(int i = 0; i < mFields.size(); ++i) { Field *f = mFields[i]; if(skipUnknowns && f->IsUnknown()) continue; if(f->GetCount() == 1 || ...

lambda expression (MSVC++ vs g++)

I have the following code #include <algorithm> #include <iostream> #include <vector> #include <functional> int main() { typedef std::vector<int> Vector; int sum=0; Vector v; for(int i=1;i<=10;++i) v.push_back(i); std::tr1::function<double()> l=[&]()->double{ std::for_each(v.begin(),v.end(),[&](int n){sum += n; /...

Is it possible to specialize template with pointer to function type that way it can see all the types used in this pointer separately?

#include <iostream> template<typename T_function_type> struct pointer_wrapper { T_function_type function_pointer; explicit pointer_wrapper(T_function_type ptr) : function_pointer(ptr) { } ~pointer_wrapper() { } }; template<typename T_return, typename T_arg1, typename T_arg2> pointer_wrapper<T_return (*)(T_arg1, T_arg2)>...

Is any mainstream compiler likely to support C++0x unrestricted unions in the near future?

I keep looking, but it seems like there's zero interest from compiler developers in supporting these. To me, it seems odd - basically, current C++ has restrictions on unions that were always an irritation and never appropriate. You'd think that basically removing a few error checks would be a relatively simple way to tick an extra c++0x...

Shared pointers and building in SIP4 (was: Dynamic casting in SWIG/python?)

So I'm playing about with Python, C++0x, and SWIG 2.0. I've got a header that looks like this: #include <string> #include <iostream> #include <memory> using namespace std; struct Base { virtual string name(); int foo; shared_ptr<Base> mine; Base(int); virtual ~Base() {} virtual void doit(shared_ptr<Base> b) { cout << ...

C++0x Lambda overhead

Is there any overhead associated with using lambda expressions in C++0x (under VS2010)? I know that using function objects incurs overhead, but I'm referring to expressions that are passed to STL algorithms, for example. Does the compiler optimize the expression, eliminating what seems to appear like a function call? I started to really...

std::list< std::unique_ptr<T> >: passing it around

Say I have a std::list of class T's: std::list<T> l; When passing it into functions, I would use a reference: someFunction( std::list<T> &l ) What is the best way to pass around (the elements) of a std::list of unique_ptrs? std::list< std::unique_ptr<T> > l; Like this: someFunction( std::unique_ptr<T> ptr ) Or this: someFun...

Why is it ill-formed to have multi-line constexpr functions?

According to Generalized Constant Expressions—Revision 5 the following is illegal. constexpr int g(int n) // error: body not just ‘‘return expr’’ { int r = n; while (--n > 1) r *= n; return r; } This is because all 'constexpr' functions are required to be of the form { return expression; }. I can't see any reason that this...

Which is the default C++0x mode in Visual C++ 2010 Express?

I have just installed Visual C++ 2010 Express and I have the impression that the default mode includes C++0x features and the std::tr1 library. error C2872: 'is_same' : ambiguous symbol could be 'C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\type_traits(941) : std::tr1::is_same' Could you confirm that? If this is th...

What would a std::map extended initializer list look like?

If it even exists, what would a std::map extended initializer list look like? I've tried some combinations of... well, everything I could think of with GCC 4.4, but found nothing that compiled. ...

C++0x Lambda Support in GCC for the iPhone

Can anyone tell me if C++ lambda expressions will be supported by GCC for the iPhone in the future? Obviously Apple have their custom 'block' support so I wondered what this may eventually mean in terms of portable C++0x code to the iPhone platform? ...

C++0x : are tuples of tuples allowed?

I'm currently working on a class with a lot of templates and being able to build tuples of tuples would make it a lot easier But I tried this simple code in MSVC++ 2010: #include <tuple> void main() { auto x = std::make_tuple(std::make_tuple(5, true)); } And I get a compilation error. The same problem happens if I don't use std...

Class method with number of arguments specified by integer template parameter

Was not exactly sure how to phrase this question or what to search on so if this is the same as another question please close and redirect to the appropriate question. Suppose template<typename Type, int Size> class vector { Type data[Size]; } Is it possible to replace a constructor which takes Size number of arguments in template ...

std::tr1::function and std::tr1::bind

I have a problem using a very complicated C function in a C++ class (rewriting the C function is not an option). C function: typedef void (*integrand) (unsigned ndim, const double* x, void* fdata, unsigned fdim, double* fval); // This one: int adapt_integrate(unsigned fdim, integrand f, void* fdata, ...

C++0x passing arguments to variadic template functions

What does it mean to take a variable number of arguments by reference? Does it mean that each of the arguments are passed by reference? Consider for example the following functions which performs some processing on each its arguments: void f() // base case for recursion { } template <typename Head, typename ... Tail> void f(Head& he...

will be this initialization syntax valid in upcoming c++0x standard ?

Suppose we have following two classes: class Temp{ public: char a; char b; }; class Final{ private: int a; char b; char c; public: Final(Temp in):b(in.a),c(in.b){} //rest of implementation }; can we initialize an object of the Final class with following syntax in upcoming c++0x standard: Final obj(Temp{'a','b'}); ...

Has any "big name entity" published C++0x syntax best practices

Although this "conversation" could quickly degenerate into something like "this is how I think ..." the question is not. Has any "big name entity" (e.g., google or the likes, Scott Meyers or the likes, etc.) published anything freely available which dictates/suggests what they feel the syntax guides lines for their code base should be f...

Is it possible to transform the types in a parameter pack?

Is it possible to transform the types of a parameter pack and pass it on? E.g. given the following: template<class... Args> struct X {}; template<class T> struct make_pointer { typedef T* type; }; template<class T> struct make_pointer<T*> { typedef T* type; }; Can we define a template magic or something similar so that the follow...

relation between access specifiers and using initializer lists for POD types in c++0x.

take two following classes: class Test1{ public: Test1()=default; Test1(char in1,char in2):char1(in1),char2(in2){} char char1; char char2; }; class Test2{ public: Test2()=default; Test2(char in1,char in2):char1(in1),char2(in2){} private: char char1; char char2; }; I know in c++0x both of these classes are considered...