I have a simple program that I am attempting to use to test C++17's class template argument deduction.
#include <iostream>
#include <list>
int main(int argc, const char * argv[]) {
const char* a = "Hello";
std::list x(1, a);
return 0;
}
I would like to std::list to deduce the list having type const char*
. However when attempting to run this code I obtain the error No viable constructor or deduction guide for deduction of template arguments of 'list'
. Specifically the constructor that should be matched to this list(size_type __n, const value_type& __x);
reports an error saying:
Candidate template ignored: substitution failure [with _Tp = const char *, _Alloc = std::__1::allocator<const char *>]: 'size_type' is a protected member of 'std::__1::__list_imp<const char *, std::__1::allocator<const char *> >'
I am curious why this does not work and yet a program like this is completely well formed with std::pair
able to easily deduce the arguments:
#include <iostream>
#include <list>
int main(int argc, const char * argv[]) {
const char* a = "Hello";
std::pair x(1, a);
return 0;
}
Thank you.
explicit
on the constructor probably makes a difference. – Eljay