Можете ли вы объяснить мне странное поведение с прямыми ссылками в MS VS 2017? Конструкторы для rvalue std :: strings (a2 & a3) получают пустые строки.
#include <string>
#include <iostream>
#include <type_traits>
using namespace std;
class A {
string text{};
public:
template <typename T,
typename = typename enable_if_t< !is_base_of_v<A, decay_t<T>> &&
!is_integral_v<remove_reference_t<T>> >>
explicit A(T&& str) : text(forward<T>(str)) {
cout << str << endl;
}
explicit A(int x) : text(to_string(x)) {}
};
int main()
{
string s = "hello"s;
A a1(s);
A a2(" world"s); // why?
A a3(string(" world")); // why?
A a4(" world");
A a5(34);
A a6(a2);
return 0;
}