C++ Logo

STD-DISCUSSION

Advanced search

Subject: Should the constructor of std::reference_wrapper be explicit?
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2021-03-26 13:32:43


Consider the following code snippet.
 
    int x = 10;
    std::reference_wrapper<int> rx( x );
    std::swap( rx, x );
 
The compiler will issue an error because either rx can be implicitly converted to the type int or x can be implicitly converted to the type std::reference_wrapper<int>.
 
So a pair of questions are arising.
 
Should the constructor of the class template std::reference_wrapper be explicit?
What is the reason that the constructor is implicit? Is that so necessary?
 
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
 



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups