jeudi 4 mai 2017

Templated template specialization for template argument

Say you have the following:

SomeType *x;
std::vector<std::unique_ptr<SomeType>> v;

And you want to call a function like this:

do_something(v.begin(), v.end(), x);

Say do_something is templated, and you want to make a specialization for the case of container<unique_ptr<T>>. Even if not for specialization, let's simply say we want to have the container templatized but always assuming inside it is a unique_ptr.

I tried the following:

template<template <typename X, typename Y> class C, typename T, typename Allocator>
inline int do_something(typename C<std::unique_ptr<T>, Allocator>::iterator first,
                        typename C<std::unique_ptr<T>, Allocator>::iterator last,
                        const T* value)
{ ... }

But g++, clang and cl.exe all fail to deduce the type of C. What's ambiguous here? And what can I do about it?

Aucun commentaire:

Enregistrer un commentaire