Questions tagged [c++11]

Use this tag for code that must compile as C++11 (not using any features introduced in C++14 or later).

C++11 is the name of a version of the C++ standard approved in the year 2011. It replaced the previous standard, C++03, adding various core language changes and fixes, and an improved and expanded standard library. C++11 had earlier been referred to as C++0x, because it was originally expected to be published before 2010.

The ISO standard, 14882:2011, is withdrawn from the ISO website. The final draft was approved by the C++ working group on the 25th of March 2011. The publicly-available draft closest to C++11 is N3337, which has only editorial differences from the full standard.

Later versions of the language standard were approved and published in 2014 and 2017 (C++14 and C++17 respectively), and questions related to them bear the tags and here on StackOverflow. Each of these supersedes the previous, just as C++11 superseded C++03.

Please tag questions about C++11 with the tag, along with the tag.

Resources

New and Changed Features

53784 questions
29
votes
3 answers

So why is i = ++i + 1 well-defined in C++11?

I've seen the other similar questions and read the defect about it. But I still don't get it. Why is i = ++i + 1 well-defined in C++11 when i = i++ + 1 is not? How does the standard make this well defined? By my working out, I have the following…
Joseph Mansfield
  • 100,738
  • 18
  • 225
  • 303
29
votes
6 answers

Inserting a variadic argument list into a vector?

Forgive me if this has been answered already, as I couldn't find it... Basically I have an object that needs to take a variadic argument list in it's constructor and store the arguments in a vector. How do I initialize a vector from a the arguments…
fredbaba
  • 1,326
  • 1
  • 14
  • 24
29
votes
2 answers

I want to kill a std::thread using its thread object?

Possible Duplicate: C++0x thread interruption I am trying to kill/stop a c++ std::thread by using its thread object. How can we do this?
CPS
  • 667
  • 2
  • 6
  • 8
29
votes
4 answers

Design principles behind std::ratio<>

I was looking at the class std::ratio<> from the C++11 standard that allows to make compile-time rational arithmetic. I found the template design and the operations implemented with classes overly complex and did not find any reason why they could…
Morwenn
  • 19,202
  • 10
  • 89
  • 142
29
votes
2 answers

Why is unique_ptr(T*) explicit?

The following functions do not compile: std::unique_ptr foo() { int* answer = new int(42); return answer; } std::unique_ptr bar() { return new int(42); } I find this a bit inconvenient. What was the rationale for making…
fredoverflow
  • 237,063
  • 85
  • 359
  • 638
29
votes
2 answers

C++11 anonymous union with non-trivial members

I'm updating a struct of mine and I was wanting to add a std::string member to it. The original struct looks like this: struct Value { uint64_t lastUpdated; union { uint64_t ui; int64_t i; float f; bool b; }; }; Just adding…
OmnipotentEntity
  • 14,886
  • 5
  • 58
  • 93
28
votes
2 answers

boost::thread_group in C++11?

Is there anything like boost::thread_group in C++11? I'm just trying to port my program from using boost:thread to C++11 threads and wasn't able to find anything equivalent.
AbuBakr
  • 938
  • 2
  • 10
  • 22
28
votes
2 answers

Does anyone have information on using operator""?

Bjarne Stroustrup gave a keynote presentation today for the Going Native 2012 conference. In his presentation, he discussed the issue of enforcing correct units. His elegant (IMHO) solution to this involved using an operator I have never heard of…
Joseph Buntic
  • 263
  • 2
  • 5
28
votes
2 answers

Does C++11 have wrappers for dynamically-allocated arrays like Boost's scoped_array?

I often need to deal with dynamically-allocated arrays in C++, and hence rely on Boost for scoped_array, shared_array, and the like. After reading through Stroustrup's C++11 FAQ and the C++11 Reference Wiki, I could not find a suitable replacement…
void-pointer
  • 12,317
  • 11
  • 40
  • 60
28
votes
4 answers

Move Constructors and Static Arrays

I've been exploring the possibilities of Move Constructors in C++, and I was wondering what are some ways of taking advantage of this feature in an example such as below. Consider this code: template class Foo { public: Foo() { …
Zeenobit
  • 4,506
  • 3
  • 30
  • 45
28
votes
1 answer

best way to do variant visitation with lambdas

I want to inline visitation of variant types with lambdas. At the moment i have the following code: struct Foo { boost::variant< boost::blank , int , string , vector< int > > var; template
lurscher
  • 23,085
  • 26
  • 113
  • 178
28
votes
2 answers

GCC error: cannot convert 'const shared_ptr<...>' to 'bool' in return

I'm switching to GCC 4.6.1, and it starts to complain about code which works fine with GCC 4.4 and MSVC10. It seems that it doesn't want to convert between shared_ptr and bool when returning from a function like this: class Class {…
Anteru
  • 18,283
  • 10
  • 72
  • 117
28
votes
4 answers

Why is the size of make_shared two pointers?

As illustrated in the code here, the size of the object returned from make_shared is two pointers. However, why doesn't make_shared work like the following (assume T is the type we're making a shared pointer to): The result of make_shared is one…
Clinton
  • 20,364
  • 13
  • 59
  • 142
28
votes
4 answers

Should we use constexpr everywhere we can?

We obviously can't make everything constexpr. And if we don't make anything constexpr, well, there won't be any big problems. Lots of code have been written without it so far. But is it a good idea to slap constexpr in anything that can possibly…
R. Martinho Fernandes
  • 209,766
  • 68
  • 412
  • 492
28
votes
3 answers

Passing/Moving parameters of a constructor in C++0x

If I have a constructor with n parameters such that any argument to that can be an rvalue and lvalue. Is it possible to do support this with move semantics for the rvalues without writing 2^n constructors for each possible rvalue/lvalue combination?
Opt
  • 4,628
  • 3
  • 24
  • 28
1 2 3
99
100