Are implicit conversions allowed with std :: tie?

C ++ 11 implies implicit conversions allowed with std :: tie?

The following code compiles and runs, but I'm not sure what happens behind the scenes or if it is safe.

std::tuple<float,float> foo() { return std::make_tuple(0,0); } double a, b; std::tie(a,b) = foo(); // a and b are doubles but foo() returns floats 
+7
c ++ c ++ 11 tuples stdtuple
source share
1 answer

It happens that the version of the tuple assignment operator template is used

 template< class... UTypes > tuple& operator=(tuple<UTypes...>&& other ); 

which moves - assigns individual members of the set one by one, using their own move destination semantics. If the corresponding members are implicitly converted, they get an implicit conversion.

This is basically a natural extension of similar functionality to std::pair , which we have been enjoying for a long time.

+14
source share

All Articles