Articles & Books

C++ String to Int -- Ivan Neeson

kumobius.PNGA nice comparison on converting a string to int:

C++ String to Int

by Ivan Neeson

From the article:

In this post I will compare the following methods for parsing a string into an integer in C++:

  • Manually
  • atoi()
  • strtol()
  • sscanf()
  • std::stoi (C++11 only)
  • std::istringstream
  • Boost.LexicalCast
  • Boost.LexicalCast with C locale
  • Boost.Spirit.Qi
  • Boost.Coerce

But first lets look at the requirements...

Overload 116 available

overload-116.PNGOverload 116 is now available. It contains the following articles, and more:

 

Overload 116

Auto -- A Necessary Evil? Part 2 -- Roger Orr

When is the use of auto good, and when is it evil?

Dynamic C++, Part 2 -- Alex Fabijanic

Alex Fabijanic and Richard Saunders continue to explore dynamic solutions in C++.

Portable String Literals in C++ -- Alf Steinbach

How hard can it be to make a file in C++ with international text literals in its name? Alf Steinbach shows us how to write a file called π.recipe.

Hard Upper Limit on Memory Latency -- Sergey Ignatchenko

How low can latency really get?

 

... and more!

An Important Move Optimization Is Nearly Invisible -- Andrew Koenig

Today in Dr. Dobb's:

An Important Move Optimization Is Nearly Invisible

by Andrew Koenig

From the article:

Last week, we looked at subtle differences between copying and moving a container (a string in this example) in the context of passing arguments to functions. Curiously, one of the biggest differences between copying and moving happens in code that we don't write. ...

The improvements in robustness and functionality that stem from moving instead of copying are, in my view, at least as important as the optimization. ...

GotW #94 Solution: AAA Style (Almost Always Auto) -- Herb Sutter

The solution to the latest GotW problem is now available:

GotW #94 Solution: AAA Style (Almost Always Auto)

by Herb Sutter

From the article:

4. When declaring a new local variable x, what advantages are there to declaring it using auto and one of the two following syntaxes:

(a) auto x = init; when you don’t need to commit to a specific type? (Note: The expression init might include calling a helper that performs partial type adjustment, such as as_signed, while still not committing to a specific type.)

(b) auto x = type{ init }; when you do want to commit to a specific type by naming a type?

Open Multi-Methods for C++11, Part 1 -- Jean-Louis Leroy

jean-louis-leroy.pngNew on Code Project:

Open Multi-Methods for C++11, Part 1

by Jean-Louis Leroy

Note: We recommend first reading this C++ multimethods paper coauthored by Bjarne Stroustrup for more background.

From the article:

This article is the first in a series about open multi-methods for C++11. In this installment, I will explain what they are, how they fit in the object-oriented paradigm, and make controversial statements.

Subsequent articles will present a new library that implements open multi-methods, using the facilities provided by C++11 (in particular, variadic templates). The library's salient features are: fast, constant time dispatch using compact tables; arbitrary number of virtual and non virtual arguments; access to the next most specific specialization; and support for shared libraries and dynamic loading. The series will conclude with an in-depth presentation of the internals of the library. ...

Some Optimizations Are More Important Than Others -- Andrew Koenig

From the desk of ARK:

Some Optimizations Are More Important Than Others

by Andrew Koenig

From the article:

[...] In short, the key to finding effective ways to speed up a program is to look at the parts of the program that dominate its execution time and find ways of speeding up those parts that require relatively little programmer effort to implement.

With this background in mind, let's think about moving data rather than copying it. Suppose, for example, that we have two functions, each of which takes a string argument: ...

Universal References and the Copy Constructor -- Eric Niebler

The "universal references" term is getting traction:

Universal References and the Copy Constructor

by Eric Niebler

From the article:

At the most recent NWCPP meeting in Redmond, WA, the always-entertaining Scott Meyers shared his latest insights about so-called “universal references” and their pitfalls. In particular, he was warning about the hazards of overloading on universal references. His advice was good, I thought, but missed some important corner cases about the interactions between universal references and the special member functions. In this article, I show what the “special” problems are with the special member functions and universal references, and some ways to avoid the problems. ...

... 

Scott’s advice is simple and sound: avoid overloading on universal references. By which he means, don’t do this:
template<typename T>
void foo( T const & t )
  {/*...*/}

template<typename T>
void foo( T && t )
  {/*...*/}

In the code above, the author presumably wanted all lvalues to go to the first and all rvalues to go to the second. But that’s not what happens. What happens is this: ...