Reputation: 105
I'm trying to implement a String. I want to convert the String to lower case, so called boost::to_lower_copy(m_s)
. In fact, m_s
is of type std::string
. My question is how return {boost::to_lower_copy(m_s)};
works in function to_lower_copy()
. How could it return a String type?
Thanks a lot.
class String {
std::string m_s;
public:
String(const std::string s) : m_s(s) { }
String to_lower_copy() const {
return {boost::to_lower_copy(m_s)};
}
};
Upvotes: 0
Views: 168
Reputation: 238311
attr(optional) return braced-init-list ;
is alternative return statement syntax introduced in C++11. It copy-list-initializes the return value of the function. The compiler knows the type that the function returns, because it is part of the declaration.
Upvotes: 1