c++0x

How can moved objects be used?

After moving an object, it must be destructable: T obj; func(std::move(obj)); // don't use obj and let it be destroyed as normal But what else can be done with obj? Could you move another object into it? T obj; func(std::move(obj)); obj = std::move(other); Does this depend on the exact type? (E.g. std::vector could make specific ...

std::transform using C++0x lambda expression

How is this done in C++0x? std::vector<double> myv1; std::transform(myv1.begin(), myv1.end(), myv1.begin(), std::bind1st(std::multiplies<double>(),3)); Original question and solution is here. ...

style in binding a reference to object-or-dummy

What is the best way to bind an rvalue reference to either a given object or a temporary copy of it? A &&var_or_dummy = modify? static_cast<A&&>( my_A ) : static_cast<A&&>( static_cast<A>( my_A ) ); (This code doesn't work on my recent GCC 4.6… I recall it working before, but now it always returns a copy.) On...

"no base classes of the same type as the first non-static data member"

I asked this a while ago on comp.std.c++ and got no reply. I'm just going to quote my post there with little modification. Is the last requirement of standard-layout classes, 9/6, necessary or useful? A footnote explanation is provided: This ensures that two subobjects that have the same class type and that belong to the sa...

Choosing between std::map and std::unordered_map

Now that std has a real hash map in unordered_map, why (or when) would I still want to use the good old map over unordered_map on systems where it actually exists? Are there any obvious situations that I cannot immediately see? ...

C++ unique_ptr and map

...

Shared resource management in multithreaded application shared_ptr?

I have to share a BLOB in a multithreaded application and and I'm currently looking into shared_ptr/weak_ptr approach, but I'm not exactly sure it is correct. There is a worker thread that creates a resource class (new CResource). CResource can be quite large, so I want to avoid extra copies. Then there is another UI thread, I want to ...

C++0x: conditional operator, xvalues, and decltype

I am reposting a comp.std.c++ Usenet discussion here because that group has become very unreliable. The last few posts I've submitted there have gone into the void, and activity has all but ceased. I doubt I've been banned and/or everyone else just lost interest. Hopefully all interested people will find this discussion, and there will b...

Deleting virtual functions in C++0x

It isn't clear what happens if I delete a virtual method in C++0x: virtual int derive_func() = delete; Does this mean this class and everything that inherits from it can not define/implement the derive_func() method? Or is this illegal/compile error? ...

Standard library tags

I use tag files for code completion and for a quick, inline view of parameters, overloads, files (where declared), etc. Where can I find freely available tags for the C99, C++03, and C++0x standard libraries? (C89 would be better than nothing, but I'd rather have C99.) I prefer tags without cruft; e.g. implementations use reserved nam...

Searching std::unordered_set by hash value and predicate

How can I search a std::unordered_set knowing hash value and having some predicate object? (The predicate determining equivalence by pred(x) && pred(y) meaning x == y.) ...

Does C++0x for loop allow new or better optimizations?

In C++0x we can now do : void dosomething( std::vector<Thing>& things ) { for( Thing& thing : things ) { dofoo( thing ); wiizzz( thing ); tadaa( thing ); } } I know that the addition and use of lambda is syntactic sugar but it provide interesting optimization opportunities. What about the for loop...

How do non-intrusive smart pointers behave with respect to inheritance and multiple inheritance?

I am using C++. C++0x using Visual Studio 2010 to be correct. Suppose I have a class Z. To make it safer in my application to work with pointers to this class, I can consistently use smart pointers (shared pointer, weak pointer). Now this class Z inherits from a class X. Some parts of my application will work with pointers to class ...

C++0x Smart Pointer Comparisons: Inconsistent, what's the rationale?

In C++0x (n3126), smart pointers can be compared, both relationally and for equality. However, the way this is done seems inconsistent to me. For example, shared_ptr defines operator< be equivalent to: template <typename T, typename U> bool operator<(const shared_ptr<T>& a, const shared_ptr<T>& b) { return std::less<void*>()(a.get(...

std::future exception on gcc experimental implementation of C++0x

Hi all, I'm experimenting with C++0x threading, partially implemented in gcc 4.5 and I've got a problem, which I can't understand. Let's have a look on this code #include <future> #include <iostream> int main() { std::cout << std::async([]() { return 10; }).get() << std::endl; } it's quite simple and should work, but it's no...

Is i += ++i undefined behavior in C++0x?

I'm very convinced with the explanation I've found that said that i = ++i is not undefined as far as C++0x is concerned, but I'm unable to judge whether the behavior of i += ++i is well-defined or not. Any takers? ...

Plain Old Data types with private members?

Is Demo a POD type in C++03? struct Demo { private: int x; int y; }; C++03, §9p4: A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor. ...

Handle std::basic_string<> with different type arguments

I want to implement a c++ library, and like many other libs I need to take string arguments from the user and giving back strings. The current standard defines std::string and std::wstring (I prefer wstring). Theoretically I have to implement methods with string arguments twice: virtual void foo(std::string // convert internally from ...

Passing a boost::unordered_set as the result map to boost::split

Does anyone know if it's kosher to pass a boost::unordered_set as the first parameter to boost::split? Under libboost1.42-dev, this seems to cause problems. Here's a small example program that causes the problem, call it test-split.cc: #include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/split.hpp> #in...

Are C++ Constructor delegates already available in VS2008?

Hello there SOers, I cant seem to find any useful information whether constructor delegates that are proposed for C++0x are already available in Visual Studio 2008 / 2010. I tried to use them and got pretty strange errors, but I can't test this in VS2010 currently. Can anyone tell me if they are available already? cheers, Tom ...