template<class> struct Printer;
// I want this to match std::vector (and similar linear containers)
template<template<class, class...> class T, class TV, class... TS>
struct Printer<T<TV, TS...>> { ... };
// I want this to match std::map (and similar map-like containers)
template<template<class, class, class...> class TM, class TK, class TV, typename... TS>
struct Printer<TM<TK, TV, TS...>> { ... }
int main()
{
// Both of these match the second specialization, which is only intended
// for std::map (and similar map-like containers)
Printer<std::vector<int>>::something();
Printer<std::map<int, float>>::something();
}
는 std::vector
및 std::map
두 번째 전문화 일치합니다. 나는 std::vector
의 할당 자 매개 변수가 과 일치하게되었는데, 이는 std::map
의 값을위한 것입니다. 제 전문화와명확 템플릿 특수화는
I 일치 어떻게 std::vector
(컨테이너 선 등) 및 제 하나 std::map
(다른 키값 용기)? 여기
'template' 인수의 개수는 문제를 해결하기위한 끔찍한 방법입니다. 즉, 깨지기 쉽고 구현에 대한 세부 사항에 달려 있습니다. – Yakk
올바른 (또는 적어도 표준화 된) 용어는 ** 순차적 컨테이너 ** 및 ** 연관 컨테이너 **입니다. * nb,이 의견은 Google보다 더 많은 것입니다. * – Orwellophile