CppCon 2016: STL Algorithms - why you should use them, and how to write your own--Marshall Clow

Have you registered for CppCon 2017 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2016 for you to enjoy. Here is today’s feature:

STL Algorithms - why you should use them, and how to write your own

by Marshall Clow

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

One of the most powerful features of the C++ standard library is the collection of basic algorithms. Everyone knows about sort and copy, but there are is a lot of powerful capabilities in the other algorithms as well. In this talk, I will explore some of the algorithms in the library, and give a rationale for writing your own, along with examples.

The motivation for writing your own algorithms is that you can create generic building blocks that can be used over and over again in your library or application, and which will allow your to program at a higher level of abstraction. Instead of thinking, "how do I sort this vector", you just call std::sort. The same should apply to the algorithms that are specific to your domain - once you write them.

P0616R0: de-pessimize legacy algorithms with std::move -- Peter Sommerlad

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: P0616R0

Date: 2017-06-06

de-pessimize legacy <numeric> algorithms with std::move

by Peter Sommerlad

Excerpt:

Acknowledgements

  • LEWG in Kona for inspiring me to write this paper.
  • Howard Hinnant for "being OK" with the change and telling me that he wasn’t brave enough for C++11 at the time to change it, when it would not have been a potentially breaking change for pathological cases.

P

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: P0616R0

Date: 2017-06-06

de-pessimize legacy <numeric> algorithms with std::move

by Peter Sommerlad

Excerpt:

Acknowledgements

  • LEWG in Kona for inspiring me to write this paper.
  • Howard Hinnant for "being OK" with the change and telling me that he wasn’t brave enough for C++11 at the time to change it, when it would not have been a potentially breaking change for pathological cases.

P0506R1: use string_view ... instead of const string &/const char* -- Peter Sommerlad

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: P0506R1

Date: 2017-06-06

use string_view for library function parameters instead of const string &/const char *

by Peter Sommerlad

Excerpt:

With basic_string_view there is no longer a reason to keep library APIs that have overloads taking std::string const & and char const * parameter types. Both should be replaced by a single version taking a std::string_view.

Acknowledgements — LEWG in Issaquah for proposing me to write this paper, even when it can not make it into C++17.

Changes from previous versions 4.1 p0506r0

  • removed unnecessary Allocator template parameter
  • change layout in regex adaptation to see changes easier piecewise judgement
  • adjust latex to most current std.tex macros
  • adjust to new standard chapter numbering
  • make regex_search allocator aware again by taking the allocator from a string parameter.

P0448R1: A strstream replacement using span<charT> as buffer -- Peter Sommerlad

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: P0448R1

Date: 2017-06-07

A strstream replacement using span<charT> as buffer

by Peter Sommerlad

Excerpt:

This paper proposes a class template basic_spanbuf and the corresponding stream class templates to enable the use of streams on externally provided memory buffers. No ownership or re-allocation support is given. For those features we have string-based streams. ...

Today, with span we actually have a library type representing such buffers views we can use for specifying (and implementing) such streams. They can be used in areas where dynamic (re-)allocation of stringstreams is not acceptable but the burden of caring for a pre-existing buffer during the lifetime of the stream is manageable.

Changes from p0448r0

  • provide explanation why non-copy-ability, while technically feasible, is an OK thing.
  • remove wrong Allocator template parameter (we never allocate anything).
  • adhere to new section numbering of the standard.
  • tried to clarify lifetime and threading issues.

P0408R2: Efficient Access to basic_stringbuf’s Buffer -- Peter Sommerlad

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: P0408R2

Date: 2017-06-07

Efficient Access to basic_stringbuf’s Buffer

by Peter Sommerlad

Excerpt:

This paper proposes to adjust the API of basic_stringbuf and the corresponding stream class templates to allow accessing the underlying string more efficiently.

N4666: National Body Comments: ISO/IEC PDTS 22277, C++ Extensions for Coroutines -- Barry Hedquist

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4666

Date: 2017-06-05

National Body Comments: ISO/IEC PDTS 22277, C++ Extensions for Coroutines

by Barry Hedquist

Excerpt:

Attached is SC22 N5205, a complete set of National Body Comments submitted to JTC1 SC22 in response to the SC22 N5193, Ballot for ISO/IEC PDTS 22277, C++ Extensions for Coroutines.

These comments are to be addressed at the next WG21 meeting in Toronto, July 10 - 15, 2017.

Document numbers referenced in the ballot comments are WG21 documents unless otherwise stated.

CppCon 2016: High Performance Code 201: Hybrid Data Structures--Chandler Carruth

Have you registered for CppCon 2017 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2016 for you to enjoy. Here is today’s feature:

High Performance Code 201: Hybrid Data Structures

by Chandler Carruth

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Modern programs’ performance characteristics are often dictated by their data. Whether the cache locality of data access, the size of working set, or avoiding costly memory allocation overhead. Unfortunately, the standard C++ library data structures range from adequate to terrible at controlling these aspects, and they don’t provide any of the core mechanisms needed for extremely efficient data structure design.

This talk will present the core concepts of designing high performance data structures in C++. It is based on years of experience in the LLVM compiler as well as several other large code bases. From these principles, the talk will propose a suite of data structures that provide performance without loss of generality or functionality. As much as this talk will present specific data structure designs, its primary intent will be to give an understanding of what makes these structures have greater performance than more naive approaches.

Quick Q: When is an rvalue evaluated?

Quick A: When it is assigned.

Recently on SO:

When is an rvalue evaluated?

s2 binds to the expression s1 + s1, but is this evaluated at the time s2 is assigned

Yes.

And also would s2 hold memory for a temporary string?

Precisely, s2 is bound to a temporary std::string.

s1 + s1 will produce a temporary std::string, which will be bound to the reference s2 (and its lifetime is extended to the lifetime of the reference). Then s2 += "Test";, performs operator+=() on  s2, i.e. the temporary std::string.