c++0x

When move ctor will be invoked?

Given class: class C { public: C() { cout << "Dflt ctor."; } C(C& obj) { cout << "Copy ctor."; } C(C&& obj) { cout << "Move ctor."; } C& operator=(C& obj) { cout << "operator="; return obj; } C& operator=(C&& obj) { cout << "Move oper...

GCC std::thread problem

I am using GCC 4.5.0 with the Eclipse IDE (if that matters) on Windows via MinGW. I'm using the -std=c++0x flag. I find that _GLIBCXX_HAS_GTHREADS still isn't defined, so thread for me still isn't a member of namespace std. -- or perhaps it is something else. What does one do to get C++0x threading support with GCC? P.S. It doesn't r...

can we pass arrays as arguments to functions by this syntax, under upcoming c++0x standards ?

suppose we have following function: void someFunction(int * araye){ for (int i=0;i<5;i++) cout <<araye[i]<<' '; cout <<'\n'; } can we pass an array to this function by following syntax, under upcoming c++0x standards? : someFunction({1,2,3,4,5}); if that's true, will we even be able to use this syntax in any case in which, arra...

How to initialize with multiple return values in c++(0x)

tuple in boost and TR1/c++0x provides a convenient (for the writer of the function) method to return two values from a function--however it seems to damage one major feature of the language for the caller: the ability to simply use the function to initialize a variable: T happy(); const auto meaningful_name(happy()); // RVO means no exc...

C++0x "Hello Concurrent World" immediately segfaults on g++/linux?

Browsing through a Currency in C++0x book and thought I would give the sample code a run. It is as basic as it gets. #include <iostream> #include <thread> void hello() { std::cout<<"Hello Concurrent World\n"; } int main(int argc, char *argv[]) { std::thread t(hello); t.join(); } Compiled with: g++ -std=c++0x -g -o pg...

Use the auto keyword in C++ STL

I have seen code which use vector, vector<int>s; s.push_back(11); s.push_back(22); s.push_back(33); s.push_back(55); for (vector<int>::iterator it = s.begin(); it!=s.end(); it++) { cout << *it << endl; } It is same as for (auto it = s.begin(); it != s.end(); it++) { cout << *it << endl; } How safe is in this case the use of...

sort vector of string using templates

here is code for sort vector of string #include<iostream> #include <vector> #include <functional> #include <algorithm> #include <ostream> using namespace std; //using std::greater; int main(){ vector<string>s; s.push_back("cat"); s.push_back("antelope"); s.push_back("dog...

Using C++ lambda functions during variable initialisation

I think many of you have this kind of code somewhere: int foo; switch (bar) { case SOMETHING: foo = 5; break; case STHNELSE: foo = 10; break; ... } But this code has some drawbacks: You can easily forget a "break" The foo variable is not const while it should be It's just not beautiful So I started wondering if there was a...

Why is it so 'hard' to write a for-loop in C++ with 2 loop variables?

Possible Duplicate: In C++ why cant I write a for() loop like this: for( int i = 1, double i2 = 0; A C developer would write this: int myIndex; for (myIndex=0;myIndex<10;++myIndex) ... A C++ developer would write this to prevent the loop variable from leaking outside the loop: for (int myIndex=0;myIndex<10;++myIndex) ... ...

Is std::swap atomic in C++0x due to rvalue references?

Since we have rvalue references in C++0x it seems to me that it should be possible to implement std::swap as an atomic operation with CAS. Is this the case in the new standard, and if not why? ...

std::auto_ptr to std::unique_ptr

With the new standard coming (and parts already available in some compilers). The new type std::unique_ptr is supposed to be a replacement for std::auto_ptr. Does their usage exactly overlap (so I can do a global find/replace on my code (not that I would do this, but if I did)) or should I be aware of some differences that are not ap...

Can static combinable<T> be used as a placeholder to thread_local?

C++0x adds a new storage specifier thread_local which is not yet implemented in VS10. However the Parallel Programming Library defines a Concurrency::combinable class which has a local() function which Returns a reference to the thread-private sub-computation. Are there semantics for thread_local that can't be (easily) covered by havin...

Any good C++0x overviews?

I teach C and C++ and I was just wondering if there are good overview of the C++0x features. I am going to read the standard, but that will take time and I'm definitely going to make it for this semester (next year hopefully). For this semester I just want to make one extra lecture about C++0x (and maybe make sure that none of the taugh...

C++0x auto, decltype and template functions

I've been reading this CodeProject article on C++0x and have given it a quick try in VC2010. However I've run into a compile error and I'm at a bit of a loss as to what the problem is. #include < iostream> template <typename FirstType, typename SecondType> auto AddThem(FirstType t1, SecondType t1) -> decltype(t1 + t2) { return t1 ...

Compile-time 'String' Manipulation with Variadic Templates

Hey all, I'm currently trying to write a compile-time string encryption (using the words 'string' and 'encryption' quite loosely) lib. What I have so far is as follows: // Cacluate narrow string length at compile-time template <char... ArgsT> struct CountArgs { template <char... ArgsInnerT> struct Counter; template <char Cur, char.....

Does c++0x tuple use the new variadic templates or Boost's macro-fied tuple implementation?

I read it was based on Boost's version, but I wasn't quite sure what that meant when it came down to implementation. I know Boost does their own variadic template, but I would assume c++0x would use its own variadic templates for the new tuple. ...

Disambiguating argument-less function calls in variadic class hierarchies

I am trying to provide users of a class (MyGizmo below) that derives from a variadic hierarchy (ObjGetter below) with a simple, uncluttered way to unambiguously call a member function that takes no arguments (check() below). I can make this work with functions that take arguments (like tune() below) but I have not found a way to make it ...

How does template parameter of std::function work? (implementation)

In Bjarne Stroustrup's home page (C++0x FAQ): struct X { int foo(int); }; std::function<int(X*, int)> f; f = &X::foo; //pointer to member X x; int v = f(&x, 5); //call X::foo() for x with 5 How it works? How std::function calls foo member function? According to the template parameter int(X*, int), is &X::foo converted from the memb...

Disabling C++0x features in VC 2010?

Does C++0x mode in VC++ 2010 has an off switch? I am working on a project that supposed to compile on non 0x compilers, and therefore I want to compile against the current standard. (Even if non of the new features are being used directly, there are still subtleties that makes C++0x more premissive). The closest switch I found was Confi...

for each in GCC and GCC version

hi how can I use for each loop in GCC? and how can i get GCC version? (in code) ...