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...
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...
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([]() { ...
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...
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 ...
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...
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...
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...
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...
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 ...
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 ...
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...
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?
...
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...
Other than Microsoft's upcoming VC10?
...
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...
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...
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...
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 ...
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
...