C++Now 2014 has ended
Please visit the C++Now website.
Back To Schedule
Friday, May 16 • 9:00am - 10:30am
Value Semantics: It ain't about the syntax!

Log in to save this to your schedule, view media, leave feedback and see who's attending!

When people talk about a type as having value semantics, they are often thinking about its ability to be passed to (or returned from) a function by value. In order to do that, the C++ language requires that the type implement a copy constructor, and so people routinely implement copy constructors on their classes, which begs the question, "Should an object of that type be copyable at all?" If so, what should be true about the copy? Should it have the same state as the original object? Same behavior? What does copying an object mean?!

By value type, most people assume that the type is specifically intended to represent a member of some set (of values). A value-semantic type, however, is one that strives to approximate an abstract mathematical type (e.g., integer, character set, complex-number sequence), which comprises operations as well as values. When we copy an object of a value-semantic type, the new object might not have the same state, or even the same behavior as the original object; for proper value semantic types, however, the new object will have the same value.

In this talk, we begin by gaining an intuitive feel for what we mean by value by identifying salient attributes, i.e., those that contribute to value, and by contrasting types whose objects naturally represent values with those that don't. After quickly reviewing the syntactic properties common to typical value types, we dive into the much deeper issues that value semantics entail. In particular, we explore the subtle Essential Property of Value, which applies to every salient mutating operation on a value-semantic object, and then profitably apply this property to realize a correct design for each of a variety of increasingly interesting (value-semantic) classes.

avatar for John Lakos

John Lakos

Software Engineer, Bloomberg
John Lakos, author of Large-Scale C++ Software Design [Addison-Wesley, 1996], serves at Bloomberg LP in New York City as a senior architect and mentor for C++ software development worldwide.  He is also an active voting member of the C++ Standards Committee’s Evolution Working... Read More →

Friday May 16, 2014 9:00am - 10:30am MDT

Attendees (0)