Articles & Books

Moving an Object Does Not Destroy The Original -- Andrew Koenig

Andy's next on move semantics:

Moving an Object Does Not Destroy The Original

by Andrew Koenig

From the article:

Recall first that objects are generally moved instead of copied because the originals are about to go away. When I learned this fact, I thought at first that moving an object should destroy the original. ...

I was surprised to learn that that is not what happens. Instead, whenever a program moves an object, it must leave that object with a valid value so that it can be destroyed later. ...

 

Modern C++ Programming with Test-Driven Development -- Jeff Langr

[Ed.: This upcoming book is currently in beta. Thanks Tom for pointing it out!]

 

langr-tdd.pngI have nothing to do with this book other than I've bought the beta book and am enjoying it thus far. It fills a gap in the market very nicely.

Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better

by Jeff Langr, edited by Michael Swaine

If you program in C++ you’ve been neglected. Test-driven development (TDD) is a modern software development practice that can dramatically reduce the number of defects in systems, produce more maintainable code, and give you the confidence to change your software to meet changing needs. But C++ programmers have been ignored by those promoting TDD -- until now. In this book, Jeff Langr gives you hands-on lessons in the challenges and rewards of doing TDD in C++.

Auto: A Necessary Evil? -- Roger Orr

Roger Orr has written about the history and use of auto in ACCU's Overload 115:

Auto -- A Necessary Evil?

by Roger Orr

From the article:

The keyword auto now lets you declare variables where the compiler provides the actual type and the programmer is either unwilling or unable to name the actual type. The keyword can also be used in function definitions to let you provide the return type after the rest of the function declaration, which is useful when the return type depends on the type of the arguments.

As with any new keyword there are questions about usage –- at two levels. First of all, where and how are programmers permitted to use the new feature. Secondly, what guidance is there to sensible adoption of the new feature. I intend to start with by answering the first question and then subsequently focus on the second.

Quick Q: Are there significant differences between boost::bind and std::bind? -- StackOverflow

A few minutes ago on SO:

Should I be seeing significant differences between std::bind and boost::bind?

I'm exploring the support for C++11 on the 4.7 branch of g++ (Ubuntu/Linaro 4.7.3-2ubuntu~12.04, to be specific) and I seem to be finding differences. In particular, if I comment out the #include of boost/bind.hpp and systematically replace occurrences of boost::bind with std::bind in the Boost ASIO async client example (taken from http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp), the program no longer compiles. Any explanation for this?

 

Quick Q: What type does auto use for containers? -- StackOverflow

Quick A: std::initalizer_list. And did you know you can even do for(auto i: {1,2,3,4,5}) ?

What type does auto use for containers?

I can achieve identical output by using different containers in C++. For example . .

    std::array<int, 5> v = {1,2,3,4,5};
    for(auto i : v)
        std::cout << i << ", ";

or

    std::vector<int> v = {1,2,3,4,5};

or

    int v[] = {1,2,3,4,5};

etc.

So what container does auto use here?

    auto v = {1,2,3,4,5};
    for(auto i : v)
        std::cout << i << ", ";

Quick Q: Why does draft C++14 have both runtime-sized arrays and std::dynarray? -- StackOverflow

Several people have asked:

Why both runtime-sized arrays and std::dynarray in C++14?

Draft C++14 includes both runtime-sized arrays and the std::dynarray container. From what I can tell, the only real difference between the two is that std::dynarray has an STL interface (e.g., begin, end, size, etc.), while runtime-sized arrays do not. So why does C++14 need them both?

C++11 Regular Expression Library -- Brian Overland

New at InformIT:

C++11 Regular-Expression Library

by Brian Overland

From the article:

Regular expressions are of practical value in many programs, as they can aid with the task of lexical analysis—intelligently breaking up pieces of an input string—as well as tasks such as converting from one text-file format (such as HTML) to another.

I’ve found that when the C++11 regular expression library is explained in a straightforward, simple manner, it’s easy to use. This chapter doesn’t describe all the endless variations on the regex function-call syntax, but it does explain all the basic functionality: how to do just about anything you’d want to do.