Situation like:
#include <utility>
#include <typeinfo>
#include <iostream>
struct C1
{
char const* str;
template <typename T> operator T() const { std::cout << "Convert to " << typeid(T).name() << "\n"; return {}; }
};
struct C2
{
C2(C1 const&) { std::cout << "C2(C1)\n"; }
C2(std::initializer_list<std::pair<char const*, int>>) { std::cout << "C2(list)\n"; }
};
int main()
{
C1 c1{};
C2 c2{c1};
}
Output indicates that C2(list)
is being called.
I would like C2(C1)
to be called for C1
argument, but I need the parameters of std::initializer list to remain deducible and convertible, and I can not replace it with variadic-templated version. I just want to control the construction order, but here //2 is not even template. Suppose type std::pair can be deserialized in normal conditions. C++14 may be used