Welcome! This is where I write stuff...
List of all articles about C++0X or C++-11.
2010-06-18 CPlusPlus0X
== Getting a tool chain to experiment with To experiment with the new C++ features it is good to have . . .
2K - last updated 2011-05-20 12:29 UTC by 94.136.75.10
2010-06-19 CPlusPlus0X
= Auto is dead, long live auto The keyword auto will get a new meaning. The old meaning is something . . .
1K - last updated 2012-02-09 10:41 UTC by 94.136.75.10
2010-08-06 CPlusPlus0X
As it happens I have had a long vacation and done other stuff than thinking about the new standard. That . . .
1K - last updated 2010-08-06 21:56 UTC by host-90-233-49-169.mobileonline.telia.com
2010-11-19 CPlusPlus0X
OOPS! Other stuff came along and I have had to stop with learning more about the new features in C++. . . .
1K - last updated 2010-11-19 23:34 UTC by localhost.localdomain
2011-06-17 CPlusPlus0X
=More on type inference Together with **auto** there is a new keyword **decltype**. It is used to determine . . .
1K - last updated 2011-06-17 15:23 UTC by 94.136.75.10
2011-06-27 CPlusPlus0X
=Initializer lists How many times have you not wanted to easily initialize a container with a list of . . .
2K - last updated 2011-06-27 07:43 UTC by 94.136.75.10
2011-06-28 CPlusPlus0X
=Taking initialization one step further - Uniform Initialization Initializing containers is fine but . . .
1K - last updated 2011-06-28 11:38 UTC by 94.136.75.10
2011-07-31 CPlusPlus0X
=Range based for loops Looping over containers is a very common task so it should be easy two write and . . .
1K - last updated 2011-07-31 22:47 UTC by host-90-232-62-193.mobileonline.telia.com
2011-09-07 CPlusPlus0X
= Lambda expressions For defining small functions at the very spot they are used C++ introduces lambda . . .
2K - last updated 2011-09-15 19:51 UTC by localhost.localdomain
2011-09-15 CPlusPlus0X
=More on Lambdas As we saw in the example with computing the sum we could in the lambda bind a variable . . .
2K - last updated 2011-09-20 14:01 UTC by 94.136.75.10
2011-10-19 CPlusPlus0X
=New keyword nullptr Maybe what can be called a smaller correction in the new standard is the introduction . . .
2K - last updated 2011-10-19 15:41 UTC by 94.136.75.10
2011-11-25 CPlusPlus0X
=Getting multiple angle brackets right A mostly embarrassing thing with good old C++ was that multiple . . .
1K - last updated 2011-11-25 23:45 UTC by localhost.localdomain
2011-12-20 CPlusPlus0X
= Object construction made easier There are three things made for easier object construction. Non static . . .
3K - last updated 2011-12-20 07:04 UTC by 94.136.75.10
2012-02-08 CPlusPlus0X
= constexpr To allow more expressive constant expressions C++-11 introduces the keyword **constexpr**. . . .
2K - last updated 2012-02-08 16:44 UTC by 94.136.75.10
2012-02-09 CPlusPlus0X
= Explicit virtual overrides There were some, small!?, problems regarding controlling derivation and . . .
1K - last updated 2012-02-09 10:46 UTC by 94.136.75.10
2012-02-24 CPlusPlus0X
= Strongly typed enums The old enum definition was a bit lame. Enums were almost interchangeable with . . .
1K - last updated 2012-02-24 23:15 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-02-27 CPlusPlus0X
= Giving up on static linkage I've been struggling with getting the treading examples working but with . . .
2K - last updated 2012-02-27 21:55 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-04-18 1 CPlusPlus11
=Move semantics Copying big objects has always been a problem and somethings that you want to avoid. . . .
2K - last updated 2012-04-18 16:06 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-04-18 CPlusPlus11
Started to write under the label [[CPlusPlus11]] for the new C++11 stuff. So much time has passed since . . .
1K - last updated 2012-04-18 15:52 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-04-26 CPlusPlus11
= Moving on Time to investigate the new move semantics, or at least what I have understood about it! . . .
2K - last updated 2012-05-08 05:42 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-05-08-1 CPlusPlus11
= Changes to old habits - you need to move to! With moving available the old habit of always passing . . .
1K - last updated 2012-05-08 09:13 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-05-08 CPlusPlus11
= Still moving on One obvious place for moving objects instead of copying is when making a swap. It is . . .
2K - last updated 2012-05-08 07:52 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-05-09 CPlusPlus11
= The future of threading A major concern these days is how to handle all these cores we have available . . .
2K - last updated 2012-05-09 12:43 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-05-11 CPlusPlus11
= Unrestricted Unions Unions is somewhat of a white area on the C++ map for me. I can't remember that . . .
1K - last updated 2012-05-11 21:55 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-06-15 CPlusPlus11
= Raw String Literals A raw string is a character sequence where there are no special characters. What . . .
2K - last updated 2012-06-15 11:39 UTC by 1-1-4-2a.mal.sth.bostream.se
2012-10-10 CPlusPlus11
= Template-ized typedefs and template Aliases With C++11 we can define a typedef as a template using . . .
1K - last updated 2012-10-10 15:19 UTC by 94.136.75.111
2013-04-29 CPlusPlus11
= C++1y/C++14 Just when you have been starting to wonder when all these nice C++11 features are going . . .
1K - last updated 2013-04-29 06:57 UTC by setnip01.ericsson.net
Nytt påskrim: PåskRimValfrihetVår
Nytt rim efter en längre tids uppehåll i rimmandet. Har haft lite svårt att ta mig tid till att sitta ner och fundera. Hur som helst här är JulRimSD.
Många undrade när fortsättningen kommer och det får vi väl se helt enkelt!
With C++11 we can define a typedef as a template using the keyword using. Suppose you have a type with the template type parameter T and the template int parameter size. Now typedefs can't be templates but with the new using syntax the type can be defined like this:
template<typename T, int size> using TheType = array<T, size>;
Achieving the same result as typedef. Now we have a type, TheType?, that is a template type.
It does not end there. We can further partially bind a template using the same syntax. So if we would like to define a new type based on TheType? but with the size bound to 10 we would do like this:
template <typename T> using SizeTen = TheType<T, 10>;
This is an example on how to set the fonts in XEmacs under Windows.
(when (memq (device-type) '(mswindows)) (set-face-font 'default "Courier New:Regular:8::") (set-face-font 'buffers-tab "Courier New:Bold:8::") (set-face-font 'bold "Courier New:Bold:8::") (set-face-font 'italic "Courier New:Italic:8::"))
Since a few days now we have a new build slave for the xemacs buildbot. It is an iMac: "Mac OSX 10.6.8, iMac 3.06 GHz Intel Core i3". Thanks Raymond Toy for providing this resource.
This is not really an XEmacs thing but hit me when I tried to get gnus working with XEmacs under cygwin. It seems you need to install the openssl development package under cygwin to get the openssl command line tool. That took me some time to figure out.
Connecting to an imap server using the same setup as under Linux produced no error message about the openssl tool missing. I just got an unhelpful connection denied form gnus. That error message fooled me into a bunch of other possible error causes before I understood that it was just that the tool openssl that was missing.
A raw string is a character sequence where there are no special characters. What you see is what you get. This makes it much easier to defined a string that contains a character sequence that would be interpreted as a special char if a normal string would have been used. Sequences like \n, \t, \b etc needs special treatment if not to be interpreted as special characters.
The syntax in its most straight forward form is this:
R"(<char-sequence>)"
R for raw and "( and )" as starting and ending sequence allowing characters between be just what they are. Here are some examples of raw strings:
R"(hello "world")" -> hello "world"
R"(no newline \n or tab \t)" -> no newline \n or tab \t
R"(
Multiline "string"
is just as it is typed
)" -> Multiline "string"
is just as it is typed
As seen in the last example you can easily define large multilined text this way.
Another situation where raw strings pay off is when there are lots of chars that normally needs to be escaped. This is the situation with regular expressions where the back slash character, \, is used either to give or remove special meaning to characters. So in regular expressions defined by normal strings the back slash character itself needs to be escaped. We don't need all this extra escaping when using raw strings.
Regexp support isn't in gcc yet so I'll come back with examples later.
To complete the definition of raw strings. What if you need the terminating sequence )" in your raw string? The general definition of a raw string, which allows you to specify a delimiter sequence, solves this:
R"<delimiter>(<char-sequence>)<delimiter>"
Where delimiter is an up to 16 char sequence with no whitespace. So you can write like this using # as delimeter:
R"#(')"')#" -> ')"'
Power failure during the afternoon. Now power is back and we are online again.
Below is the report from Fortum.
Avslutade avbrott det senaste dygnet 2012-05-29 15:23 Strömavbrott i Skärholmen. Sluttid: 2012-05-29 18:18. Maximalt 349 berörda kundanläggningar.
Just the other day I saw a video that presented a new feature in Visual Studio 2011 called auto vectorization. This made me curious about the feature and whether it was available in the tools I have access to, e.g. g++.
The short answer is yes and if you use the optimization level 3, compilation flag -O3, you get this. It seems like the situation is the same for Visual Studio 2011. You get this automatically. So that is fine and end of story if you like. If you want some more details please read on.
The idea is to use the CPU registers introduced with technologies such as MMX or SSE. These vector registers can hold multiple scalar values and perform operations on them. That is a situation that occurs in a loop going over a vector.
int a[SIZE], b[SIZE], c[SIZE];
...
for (i=0; i<SIZE; i++)
{
a[i] = b[i] + c[i];
}
In the code fragment above the arithmetic in the loop can be vectorized meaning that the operations for more than one index can be performed in parallel using the vector registers. It is up to the compiler to analyse the code to figure out that the optimization can be applied.
With gcc this optimization if on by default from optimization level 3, compilation flag -O3. You can also turn it on by using the flag, -ftree-vectorize. Note however that you also need to turn on the use of the vector registers. On my x86 machine I need to add the compiler flag -msse2.
There is however another useful flag, -ftree-vectorizer-verbose. This causes the compiler to tell you if it has found a loop that it is able to optimize. This is good since compiler optimization is like a black box. You either have to run the program and measure it or analyse the assembly code to understand if the optimization took place. A verbose message is a great help in that situation so you know you are on the right track.
This must be tested of course. So I came up with this test program.
// Vectorization
#include <chrono>
#include <iostream>
using namespace std;
const int SIZE=2048;
int a[SIZE], b[SIZE], c[SIZE];
void foo ()
{
for (int j=0; j<1000000; j++)
{
for (int i=0; i<SIZE; i++)
{
a[i] = 0;
b[i] = 10;
c[i] = 100;
}
for (int i=0; i<SIZE; i++)
{
a[i] = b[i] + c[i];
}
}
}
int main()
{
auto start = chrono::steady_clock::now();
foo();
auto diff = chrono::steady_clock::now() - start;
auto ms = chrono::duration_cast<chrono::milliseconds>(diff);
cout << "It took " << ms.count() << endl;
}
In order to get some measurable execution time I had to loop over the loop one million times. The optimized version ran in 1122 milliseconds while the unoptimized program ran in 4424 milliseconds. That is something like a speed up of 4 times. This is due to that on the current machine the vector registers can store four integers at once. A vector register is 128 bits and an int is 32 bits.
Vectorization is an optimization technique that can be used automatically by a smart compiler. It is also easy to understand how it works. Programs that will benefit from it uses loops to manipulate data.
The optimization uses mechanisms that is on the CPU within the a single core. It does illustrate though how you can speed up execution by using parallelism and it helps in understanding the features in C++ AMP, Accelerated Massive Parallelism which I hope to be able to show more about in the future.