Can the following function template be made to actually act based on argument type :
#include <iostream>
#include <memory>
#include <tuple>
#include <typeinfo>
using namespace std;
using UPSTR = unique_ptr<char[]>;
template<typename... Ts>
void uprint(Ts const&... strs){
auto tp = std::tie(strs...);
auto& x = std::get<0>(tp);
if(typeid(x)==typeid(UPSTR)) cout << x.get() << endl;
// Error : no match for 'operator<<' and 'const std::unique_ptr<char []>') :
else cout << x << endl;
}
int main(){
UPSTR str = make_unique<char[]>(10); str.get()[0] = 'A';
uprint(str, "hello");
return 0;
}
?
Error from gcc 12.2 : no match for 'operator<<' and 'const std::unique_ptr<char []>')
https://godbolt.org/z/dYG9r7Koj (MSVC does compile this !)