concept normal value in category c++

appears as: normal values, normal value
Functional Programming in C++

This is an excerpt from Manning's book Functional Programming in C++.

Listing 5.9 Separating member functions for normal values and temporaries
class person_t {
public:
    person_t with_name(const std::string& name) const &     #1  
    {
        person_t result(*this);    #2  

        result.m_name = name;    #3  

        return result;    #4  
    }

    person_t with_name(const std::string& name) &&          #5  
    {
        person_t result(std::move(*this));    #6  

        result.m_name = name;    #7  

        return result;    #8  
    }

};

#1   This member function will work on normal values and lvalue references.
#2   Creates a copy of the person
#3   Sets the new name for that person. It’s OK to change the name because this person_t instance still isn’t visible from the outside world.
#4   Returns the newly created person_t instance. From this point on, it’s immutable.
#5   This one will be called on temporaries and other rvalue references.
#6   Calls the move constructor instead of the copy constructor
#7   Sets the name
#8   Returns the newly created person


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":48},{\"line\":2,\"ch\":55}],[{\"line\":11,\"ch\":48},{\"line\":11,\"ch\":50}]]"}
!@%STYLE%@!

Instead, you’ll do something smarter. As soon as you see a value with a context that should be stripped out when calling another function, think of monads. With optional values, the context is the information about whether the value is present. Because the other functions take normal values, this context needs to be stripped out when calling them (see figure 10.11).