, , - , .. static_cast<(void(*)(const int&)>(f)(r). , , . f( static_cast<const int&>( r ) ), static_cast .
int main()
{
int a = 0;
int& r = a;
f(static_cast<int const&>(r));
}
If you want to generalize this by creating modifiers for the standard library type, you can do this as follows:
f(static_cast<std::remove_reference<decltype(r)>::type const&>(r));
Since this is pretty ugly, I recommend simply defining a generic const-adder or ad-hoc that declares a link constlocally, and use this as an argument.
A common const-adder might look like this:
template< class Type >
auto const_ref( Type const& r ) -> Type const& { return r; }
source
share