c++0x

Implementing atomic<T>::store

I'm attempting to implement the atomic library from the C++0x draft. Specifically, I'm implementing §29.6/8, the store method: template <typename T> void atomic<T>::store(T pDesired, memory_order pOrder = memory_order_seq_cst); The requirement states: The order argument shall not be memory_order_consume, memory_order_acquire, nor...

C++ or C++0x - Which is a better standard?

So I've been trying to do some research and would like the opinions of other developers on this topic. I am an experienced C++ programmer and have been using the current C++ standard for some time. I have been reading articles that "C++0x will undoubtedly become the new standard." How far off are we does everyone think from making the sw...

How does a C++ compiler implement thread local storage in C++0x?

How does c++ complier implement thread local storage in C++0x I have searched this in google. But I can't find anything about this. Does anyone have any material about this ?? ...

type to int mapping

I have two c++ programs that need to have a map type -> int that is known at compile time and equal between the two programs. Furthermore, I'd like to automatically make sure at compile time that the map is one-to-one. How would you solve that? (c++0x-extensions are allowed). The first part is easy: Share a template < typename T > stru...

Dynamic matrix with contiguous storage

I want a matrix container class that has similar functionality to vector<vector<type>>, but stores elements in contiguous memory. I bet there is none in the standard library (including C++0x); does Boost provide one? ...

Detecting C++0x mode on Intel C++?

Does Intel C++ predefine some macro when compiling with Qstd=c++0x? Something like __GXX_EXPERIMENTAL_CXX0X__ in GCC? __cplusplus is still 199711. Any way to detect C++0x compilation? ...

decltype with a variadic template function

I want to write a simple adder (for giggles) that adds up every argument and returns a sum with appropriate type. Currently, I've got this: #include <iostream> using namespace std; template <class T> T sum(const T& in) { return in; } template <class T, class... P> auto sum(const T& t, const P&... p) -> decltype(t + sum(p...)) { ...

Local class template

We can have a local class defined inside a function but this class cannot be a template which is bit annoying and inconsistent. Is there any update on that in C++0x standard? ...

How to dump candidates in function overload resolution?

How can I dump candidate functions (or viable functions or best viable functions) for a function invocation? I know g++ provides an option to dump class hierarchy. (In fact, Visual Studio 2010 provides a similar option, but it's undocumented. I remember reading something about it—maybe in the VC++ team blog—but I can't remember it clea...

How to get the index of a value in a vector in C++0x for_each algorithm and lambda expression?

I have the following C++0x code (compiler- MSVC++ 10): std::vector<float> data; data.push_back(1.0f); data.push_back(1.0f); data.push_back(2.0f); // lambda expression std::for_each(data.begin(), data.end(), [](int value) { // Can I get here index of the value too? }); What I want in the above code snippet is to get the index of ...

What do I need to know about C++0x?

Possible Duplicate: Where can I learn more about C++0x? I am fairly familiar with C++03 but I still need to come to terms with C++0x so I would like to read some fairly digestible information on C++0x. I have looked at the Wikipedia but I am on the look out for something that is more readable. So is there a book or series of ...

Exceptions with Unicode what()

Or, "how do Russians throw exceptions?" The definition of std::exception is: namespace std { class exception { public: exception() throw(); exception(const exception&) throw(); exception& operator=(const exception&) throw(); virtual ~exception() throw(); virtual const char* what() const throw(); }; } A popul...

Is there a way to statically-initialize a dynamically-allocated array in C++?

In C++, I can statically initialize an array, e.g.: int a[] = { 1, 2, 3 }; Is there an easy way to initialize a dynamically-allocated array to a set of immediate values? int *p = new int[3]; p = { 1, 2, 3 }; // syntax error ...or do I absolutely have to copy these values manually? ...

C++x0 unique_ptr GCC 4.4.4

Hi, I am trying to make use of the unique_ptr from C++x0, by doing #include <memory> and comping with -std=c++0x, however it is throwing up many errors this being an example. /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/bits/unique_ptr.h:214: error: deleted function ‘std::unique_ptr<_Tp, _Tp_Deleter>::uni...

Lambda capture as const reference?

Is it possible to capture by const reference in a lambda expression? I want the assignment marked below to fail, for example: #include <cstdlib> #include <vector> #include <string> #include <algorithm> using namespace std; int main() { string strings[] = { "hello", "world" }; static const size_t num_st...

Accepting nested variadic class templates as arguments to function template.

I'm trying to make a function template that will accept two (or more) of the nested variadic class templates listed below, as arguments, and put them into another data structure that will accept different types (pair or tuple is what I'll most likely use). Here are the classes and subclasses, along with the usage of my function (the fun...

Returning a unique_ptr from a class method C++0x

If my class SomeType has a method that returns a element from the map (using the key) say std::unique_ptr<OtherType> get_othertype(std::string name) { return otMap.find(name); } that would enure the caller would recieve a pointer to the one in the map rather than a copy? Is it ok to do this, or would it try and call the copy const...

Meaning of C++0x auto keyword, by example?

Hello, auto a = (Foo<T>*)malloc(sizeof(Foo<T>)); auto *b = (Foo<T>*)malloc(sizeof(Foo<T>)); I don't think it's important that templates are there, but the question is: are a and b of the same type? g++ -std=c++0x -Wall (4.4) doesn't give any errors or warnings, but I haven't run the program so I don't know if it does the same thing. ...

Template type deduction of reference

I've been playing around with type deduction/printing using templates with code of the form: #include <iostream> template <typename T> class printType {}; template <typename T> std::ostream& operator<<(std::ostream& os, const printType<T>&) { os << "SomeType"; return os; } template <typename T> std::ostream& operator<<(std::ostr...

Eliminating temporaries in operator overloading

Note: as noted by sellibitze I am not up-to-date on rvalues references, therefore the methods I propose contain mistakes, read his anwser to understand which. I was reading one of Linus' rant yesterday and there is (somewhere) a rant against operator overloading. The complaint it seems is that if you have an object of type S then: S a...