The following code cannot compile with an error template template argument has different template parameters than its corresponding template template parameter:
#include <tuple>
#include <vector>
#include <string>
#include <iostream>
template<template<typename, typename> class Blah, typename KeyType, typename ValueType>
void print_tuploid(const Blah<KeyType, ValueType>& tup) {
std::cout << "first value: " << std::get<0>(tup) << " second value: " << std::get<1>(tup) << std::endl;
}
int main() {
auto stuff = std::make_tuple(1, 2);
print_tuploid(stuff);
}
The original intent of this code does not matter, at this point I am just trying to understand why this is considered unacceptable.
If I changed the call to std::make_tupleon std::make_pair, the code will compile and run correctly, which leads me to believe that there is something strange going on with respect std::tuple.
I initially thought that it std::tuplemight have some additional default template arguments that I didn’t know about, because if I changed the definition print_tuploidto the following, the code FORKES for both std::make_tupleand std::make_pair:
template<template<typename...> class Blah, typename KeyType, typename ValueType>
void print_tuploid(const Blah<KeyType, ValueType>& tup) {
std::cout << "first value: " << std::get<0>(tup) << " second value: " << std::get<1>(tup) << std::endl;
}
But when I tried to infer the type being deduced stuffusing the following code:
#include <tuple>
template<typename T>
class TypePrinter;
int main() {
auto stuff = std::make_tuple(1, 2);
TypePrinter<decltype(stuff)> error;
}
: implicit instantiation of undefined template 'TypePrinter<std::__1::tuple<int, int> >', , .
, , ? :
#include <iostream>
template<template<typename, typename> class Blah, typename KeyType, typename ValueType>
void print_tuploid(Blah<KeyType, ValueType>&& tup) {
std::cout << "first value: " << std::get<0>(tup) << " second value: " << std::get<1>(tup) << std::endl;
}
int main() {
auto stuff = std::make_pair(1, 2);
print_tuploid(stuff);
}
: no known conversion from 'std::__1::pair<int, int>' to 'pair<int, int> &&' for 1st argument.
, , . , .