c++0x

How can I compile GCC on a mac so compiled executables will work on earlier versions of OS X?

I'm attempting to build a program (Dwarf Fortress) that uses C++0x features that aren't well supported in the latest Leopard version of XCode. As there is also a significant speed boost from using GCC 4.5, we've decided to build our own. However, this causes the resulting executables to not work on Tiger, citing missing symbols in libc....

Placeholder for C++0x's <thread> header in MSVC++ 2010

I already use some new features from C++0x in Visual C++ 2010, like regular expressions or lambda functions. But there is one major feature that is missing: the <thread> header. Do you know any code which could act as a replacement? For the moment I'm using boost's thread, but it's not exactly the same as the standard, and it gives me ...

pure/const functions in C++0x

Hi, In C++98/C++03, there are no pure/const function keywords in the language. Has this changed in C++0x? If so, is it possible to set such a flag even on function objects (std::function)? So I can pass some function pointer or lambda functions and additional give the information that it is a pure/const function? The called function m...

Can C++0x still explicitly allocate with global operator new?

Wikipedia states: A type can be made impossible to allocate with operator new: struct NonNewable { void *operator new(std::size_t) = delete; }; An object of this type can only ever be allocated as a stack object or as a member of another type. It cannot be directly heap-allocated without non-portable trickery. (Since place...

List initializer

I am trying to declare an iterator of type std::initializer_list as it is described in this answer. But I always get this error: error: 'iterator' is not a member of 'std::initializer_list<int>' May someone guide me how to declare an iterator of type std::initializer_list? EDIT: This code for example will not work. In addition, The...

custom allocator using move for vector of thread

I'm currently learning about concurrency in C++ and came across using a vector of threads, which I believe will be possible in C++0x. However, my current compiler doesn't appear to have an implementation of move-aware containers and so I get errors generated because std::thread::thread(const std::thread&) is deleted, ie I can only use th...

Why would you "default" a copy/move constructor or a destructor?

C++0x lets you specify certain functions as defaulted: struct A { A() = default; // default ctor A(A const&) = default; // copy ctor A(A&&) = default; // move ctor A(Other); // other ctor ~A() = default; // dtor A& operator=(A const&) = default; // copy assignment A& operator=(A&&) =...

C++0x template function object inference

I'm a Scala/Java programmer looking to reintroduce myself to C++ and learn some of the exciting features in C++0x. I wanted to start by designing my own slightly functional collections library, based on Scala's collections, so that I could get a solid understanding of templates. The problem I'm running into is that the compiler doesn't s...

How to use a lambda expression as a template parameter?

How to use lambda expression as a template parameter? E.g. as a comparison class initializing a std::set. The following solution should work, as lambda expression merely creates an anonymous struct, which should be appropriate as a template parameter. However, a lot of errors are spawned. Code example: struct A {int x; int y;}; std::s...

Sorting a set<string> on the basis of length

My question is related to this. I wanted to perform a sort() operation over the set with the help of a lambda expression as a predicate. My code is #include <set> #include <string> #include <iostream> #include <algorithm> int main() { using namespace std; string s = "abc"; set<string> results; do { for (int n = 1; n <= s....

Ternary Operator

Why compiler cannot specialize this function and is there a way to force him to do so? The error I'm getting: Error 1 error C2893: Failed to specialize function template ''unknown-type' Ternary::check(bool,Left,Right)' #include "stdafx.h" #include <iostream> #include <string> using std::cout; using std::string; template<int v> stru...

C++0x Peer Constructor in VC2010

According to the C++0x spec, the following is legal class A { A(int i) : x(i) {} A() : A(0) {} int x; }; But it fails to compile ("A" is not a nonstatic data member or base class of class "A") in VC 2010. Anyone know what's wrong? ...

C++ Problem with explicit template instantiation of an operator

Hi, I have a template class that I m trying to explicitly instantiate: template<T> struct tmat2x3 { ... typedef tvec3<T> col_type; .. }; the operator is declared as follows: template <typename T> typename tmat2x3<T>::row_type operator* (tmat2x4<T> const & m, typename tmat2x3<T>::col_type const & v); I am explicitly instantiating t...

Change only parts of a type in a C++ template

Purpose and craziness aside, is there a way to achieve this in C++? template <typename P> void Q void_cast(P Q *p) const { return static_cast<P Q *>(p); } I'm effectively trying to cast a pointer to a void pointer type whilst keeping any const, restrict and other qualifiers (denoted by Q). I was under the impression there was stu...

Can someone explain rvalue references with respect to exceptions?

Lets say I've this exception class: struct MyException : public std::exception { MyException(const std::exception &exc) : std::exception(exc) { cout << "lval\n"; } MyException(std::exception &&exc) : std::exception(std::forward<std::exception>(exc)) { cout << "rval\n"; } }; ... ... try { thr...

Segfault in C++ calling virtual method on object created in pre-allocated buffer

Hmm... Title is a bit of a mouthful, but I'm really not sure which part of this is causing issues, I've run through it a ton of times, and can't pinpoint why... The idea is for a single Choice instance to be able to store any one value of any of the types passed in to it's template list... It's kind of like a union, except it keeps trac...

How to pass Lambda expression parameter by Reference for C++0x

Hello, I am using a C++0x lambda expression to modify values of a map. However, having difficulty passing the map iterator by reference. If I just pass the iterator, by value such as: [](std::pair<TCHAR, int > iter) it compiles fine, but the values does not get updated in the map. If I try to pass the iterator by reference, such as []...

Why wasn't yield added to C++0x?

I have been using yield in many of my Python programs, and it really clears up the code in many cases. I blogged about it and it is one of my site's popular pages. C# also offers yield – it is implemented via state-keeping in the caller side, via an automatically generated class keeps the state, local variables of the function, etc. No...

Can the 'type' of a lambda expression be expressed?

Thinking of lambda expressions as 'syntactic sugar' for callable objects, can the unnamed underlying type be expressed? An example: struct gt { bool operator() (int l, int r) { return l > r; } } ; Now, [](int l, int r) { return l > r; } is an elegant replacement for the above code (plus the necessary creation of c...

Why does this reject an enum?

Why does this code fail? #include <algorithm> int main() { int a[10]; enum { a_size = sizeof a / sizeof *a }; std::fill(a, a + a_size, a_size); } G++ 4.1.2 and 4.4.3: In function 'int main()': Line 5: error: no matching function for call to 'fill(int [10], int*, main()::<anonymous enum>)' Is this code valid C++0x? ...