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...
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...
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...
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...
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...
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...
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...
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...
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) ...
...
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?
...
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...
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...
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...
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 ...
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.....
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.
...
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 ...
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...
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...
hi
how can I use for each loop in GCC?
and how can i get GCC version? (in code)
...