C++ Logo

std-discussion

Advanced search

Re: Should the constructor of std::reference_wrapper be explicit?

From: Vladimir Grigoriev <vlad.moscow_at_[hidden]>
Date: Sat, 27 Mar 2021 12:35:48 +0300
As an example consider the following program
 
#include <iostream>
#include <functional>
void f( std::reference_wrapper<int> , std::reference_wrapper<int> )
{
    
}
void f( int, int )
{
    
}
int main()
{
    int i = 10;
    std::reference_wrapper<int> ri( i );
    
    f( i, ri );
    f( i, ri );
    
    return 0;
}
 
Here is an ambiguity in calling the function f.
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
 
 
>Пятница, 26 марта 2021, 21:48 +03:00 от Vladimir Grigoriev via Std-Discussion <std-discussion_at_[hidden]>:
>
>I am sorry. I made an incorrect resume about the error. Nevertheless the questions about implicit constructor are actual.
>
>
>You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com


>>Пятница, 26 марта 2021, 21:33 +03:00 от Vladimir Grigoriev via Std-Discussion < std-discussion_at_[hidden] >:
>>
>>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 mailing list
>>Std-Discussion_at_[hidden]
>>https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
>--
>Std-Discussion mailing list
>Std-Discussion_at_[hidden]
>https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
 

Received on 2021-03-27 04:35:54