Failed to instantiate specialized template class dispatched from constraints

Viewed 59

As a follow up from a previous question: Giving an arbitrary container, deduce a container type of a related type, where @marek-r suggested to create template specializations like:

template<template<typename> typename Wrapper, typename Container>
struct repack;

template<template<typename> typename Wrapper, typename ValueT, std::size_t N>
struct repack<Wrapper, std::array<ValueT, N>>
{
    using type = std::array<Wrapper<ValueT>, N>;
};

template<template<typename> typename Wrapper, typename ValueT>
struct repack<Wrapper, std::vector<ValueT>>
{
    using type = std::vector<Wrapper<ValueT>>;
};

template<template<typename> typename Wrapper, typename Key, typename Value>
struct repack<Wrapper, std::map<Key, Value>>
{
    using type = std::map<Wrapper<Key>, Wrapper<Value>>;
};

or link: https://godbolt.org/z/naz9v48vb


By trying to make this more generic, I swapped vector and map with templated template parameter, and dispatch each solution using c++20 constraints, by checking if the value_type is the same as pair<const key_type, mapped_type>:

template<template<typename> typename Wrapper, 
         template<typename, typename> typename Mapped_Container, 
         typename Key, typename Value>
    requires std::is_same_v<
        typename Mapped_Container<Key, Value>::value_type, 
        std::pair<const typename Mapped_Container<Key, Value>::key_type, typename Mapped_Container<Key, Value>::mapped_type>>
struct repack<Wrapper, Mapped_Container<Key, Value>>
{
    using type = Mapped_Container<Wrapper<Key>, Wrapper<Value>>;
};

template<template<typename> typename Wrapper, 
         template<typename> typename Unmapped_Container, typename Value>
struct repack<Wrapper, Unmapped_Container<Value>>
{
    using type = Unmapped_Container<Wrapper<Value>>;
};

However this solution seems to only compiles in gcc and fails in clang and msvc: https://godbolt.org/z/zzY7WvoEd

Where clang would report the error: "implicit instantiation of undefined template" and msvc seems to fail to specialize alias template.

Am I missing something here, or did I hit a compiler extension?

0 Answers
Related