c++0x

Can't create map of MoveConstructibles

Hello, I have a class containing a std::unique_ptr<> and I want to put instances of this class inside of an std::map<>. I thought one of the things that motivated the introduction of move semantics to C++ was the possibility of putting things like unique_ptrs inside standard containers (and that really works, in the case of vectors). Bu...

unique_ptr<> v shared_ptr<> in regards to destruction policy

I've been teaching myself the smart pointers that are part of C++0x and came across something that feels inconsistent to me. Specifically, how the destruction policy of unique_ptr<> and shared_ptr<> are handled. For unique_ptr<>, you can specialize std::default_delete<> and from then on unless you explicitly request a different destruc...

Unable to instantiate function templates which uses decltype to deduce return type, if called from inside a lambda?

I'm trying to use C++0x, and in particular lambda expression and decltype to simplify some of my code, using the MSVC10 RC compiler. I've run into the following very odd problem: template <typename F> auto foo(F f) -> decltype(f()){ return f(); } template <typename F> void bar(F f){ f(); } int main() { bar([](){ foo([]() { ...

std::initializer_list as function argument

For some reason I thought C++0x allowed std::initializer_list as function argument for functions that expect types that can be constructed from such, for example std::vector. But apparently, it does not work. Is this just my compiler, or will this never work? Is it because of potential overload resolution problems? #include <string> #in...

Signedness of char and Unicode in C++0x

From the C++0x working draft, the new char types (char16_t and char32_t) for handling Unicode will be unsigned (uint_least16_t and uint_least32_t will be the underlying types). But as far as I can see (not very far perhaps) a type char8_t (based on uint_least8_t) is not defined. Why ? And it's even more confusing when you see that a ...

Can nullptr be emulated in gcc?

I saw that nullptr was implemented in Visual Studio 2010. I like the concept and want to start using it as soon as possible; however GCC does not support it yet. My code needs to run on both (but doesn't have to compile with other compilers). Is there a way to "emulate" it? Something like: #define nullptr NULL (but obviously that wou...

C++0x atomic implementation in c++98 question about __sync_synchronize()

I have written the followin atomic template with a view to mimicing the atomic operations which will be available in the upcoming c++0x standard. However, I am not sure that the __sync_synchronize() call I have around the returning of the underlying value are necessary. From my understanding, __sync_synchronize() is a full memory barr...

Visual Studio 2010 and std::function

I have this code: #include <iostream> #include <functional> struct A { int operator()(int i) const { std::cout << "F: " << i << std::endl; return i + 1; } }; int main() { A a; std::tr1::function<int(int)> f = std::tr1::ref(a); std::cout << f(6) << std::endl; } The aim is to pass the functor object...

C++0x - export gone, exception specs deprecated. Will this affect your code?

This latest Herb Sutter trip report on the C++0x standardisation process indicates that the committee has decided to completely drop the "export" concept for templates, and to deprecate exception specifications. I think these are both good moves, but I'm interested if anyone out there has a code base where these changes will cause them...

Function return type style

I'm learning c++0x, at least the parts supported by the Visual C++ Express 2010 Beta. This is a question about style rather than how it works. Perhaps it's too early for style and good practice to have evolved yet for a standard that isn't even released yet... In c++0x you can define the return type of a method using -> type at the end ...

Switching to C++11

We are going to start a long lasting project using C++ as the programming language. I read that C++0x is going to come out in 2011, so they called it C++11. When C++11 comes out, we will still be developing the project, and would like to know if it is possible to use any features of the new C++ standard now, to able to: code faster ...

Mixins, variadic templates, and CRTP in C++

Here's the scenario: I'd like to have a host class that can have a variable number of mixins (not too hard with variadic templates--see for example http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.103.144). However, I'd also like the mixins to be parameterized by the host class, so that they can refer to its public types (using th...

Generating tuples from tuples

Say you have a tuple and want to generate a new tuple by applying a metafunction on each type of the first one. What' the most efficient C++ metafuntion to accomplish to this task? Is it also possible to use C++0x variadic template to provide a better implementation? ...

g++ C++0x enum class Compiler Warnings

I've been refactoring my horrible mess of C++ type-safe psuedo-enums to the new C++0x type-safe enums because they're way more readable. Anyway, I use them in exported classes, so I explicitly mark them to be exported: enum class __attribute__((visibility("default"))) MyEnum : unsigned int { One = 1, Two = 2 }; Compiling thi...

Any implementations of C++0x out there?

Other than Microsoft's upcoming VC10? ...

Why is the volatile qualifier used through out std::atomic?

From what I've read from Herb Sutter and others you would think that volatile and concurrent programming were completely orthogonal concepts, at least as far as C/C++ are concerned. However, in GCC c++0x extension all of std::atomic's member functions have the volatile qualifier. The same is true in Anthony Williams's implementation of...

c++0x, std::thread error (thread not member of std)

Hello I compiled & installed gcc4.4 using macports. When I try to compile using -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp...: #include <thread> ... std::thread t(handle); t.join(); .... The compiler returns: cserver.cpp: In member function 'int CServer::run()': cserver.cpp:48: error: 'thread' is not a member of 'st...

Const references when dereferencing iterator on set, starting from Visual Studio 2010

Starting from Visual Studio 2010, iterating over a set seems to return an iterator that dereferences the data as 'const data' instead of non-const. The following code is an example of something that does compile on Visual Studio 2005, but not on 2010 (this is an artificial example, but clearly illustrates the problem we found on our own...

Specializing a template on a lambda in C++0x

I've written a traits class that lets me extract information about the arguments and type of a function or function object in C++0x (tested with gcc 4.5.0). The general case handles function objects: template <typename F> struct function_traits { template <typename R, typename... A> struct _internal { }; template <typename ...

`enable_shared_from_this` has a non-virtual destructor

I have a pet project with which I experiment with new features of the upcoming C++0x standard. While I have experience with C, I'm fairly new to C++. To train myself into best practices, (besides reading a lot), I have enabled some strict compiler parameters (using GCC 4.4.1): -std=c++0x -Werror -Wall -Winline -Weffc++ -pedantic-errors ...