I am trying to understand std::is_convertible in C ++ 11. According to cppreference.com , std::is_convertible<T,U>::value should be evaluated as 1 iff "If an imaginary value of type T can be used in the return statement of a function returning U " The wording says nothing about where this function can be declared. What can you expect when the copy constructor U is private? What can be expected when T is an lvalue reference?
For example, consider this code:
#include <iostream>
I am using gcc-4.8.2 or clang-3.4 (there is no difference in output) and I am compiling with:
{g++|clang++} -std=c++11 -Wall -Wextra eg.cpp -o eg
Here std::is_convertible< Ref_A, A > reports 0 . However, you can see that Fact_A::f returns an object of type A , and an rvalue of type Ref_A used in its return statement. The problem is that copy constructor A is private , so the function cannot be hosted anywhere. Is the current behavior correct according to the standard?
Second question. If I delete private , the output goes to 1 1 1 . What does the last 1 mean? What is an "rvalue of type A& "? Is this a link to rvalue? As you may have noticed, I explicitly deleted the move constructor A As a result, I cannot declare Fact_A::g . But still std::is_convertible< A&, A > reports 1 .
c ++ language-lawyer c ++ 11 std typetraits
Matei david
source share