STL ref and cref functions

Why are there two functions with different names ref and cref in C ++? Why is not the only overloaded ref function? Are there some important semantic reasons?

+5
source share
1 answer

Because sometimes you want to wrap a const link to an object not const . In such cases, std::cref allows you to write

 std::cref(x) 

instead

 std::ref(static_cast<const T&>(x)) 

(where T , of course, is type x ).

+10
source

Source: https://habr.com/ru/post/1205756/


All Articles