2

Can anyone tell me the rationale for not allowing explicit specialization in non-namespace scope? Why must I do:

template <typename ...Ts>
struct types;

template <typename T, typename ...Ts>
struct types < T, Ts... > : public types<Ts...>
{
    template <typename F, int i = 0>
    struct find : public types<Ts...>::template find<F, i>
    {
    };

    template <int i>
    struct find < T, i > : public std::true_type
    {
        typedef T type;
    };
};

template <>
struct types < >
{
    template <typename F, int i = 0>
    struct find : public std::false_type
    {};
};

demo

and not:

template <typename ...Ts>
struct types;

template <typename T, typename ...Ts>
struct types < T, Ts... > : public types<Ts...>
{
    template <typename F>
    struct find : public types<Ts...>::template find<F>
    {
    };

    template <>
    struct find < T > : public std::true_type
    {
        typedef T type;
    };
};

template <>
struct types < >
{
    template <typename F>
    struct find : public std::false_type
    {};
};

demo

Adrian
  • 10,246
  • 4
  • 44
  • 110
  • 3
    http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#727 – dyp Jan 11 '15 at 00:06
  • 2
    Duplicate: [Why is partial specialziation of a nested class template allowed, while complete isn't?](http://stackoverflow.com/q/2537716) But IMHO the answer isn't really satisfying, in the light of CWG 727. – dyp Jan 11 '15 at 00:12
  • possible duplicate of [Why is partial specialziation of a nested class template allowed, while complete isn't?](http://stackoverflow.com/questions/2537716/why-is-partial-specialziation-of-a-nested-class-template-allowed-while-complete) – ruakh Jan 11 '15 at 01:04
  • 1
    Though the answers for http://stackoverflow.com/questions/2537716/why-is-partial-specialziation-of-a-nested-class-template-allowed-while-complete are useful, they don't have anything to backup their claim, mearly speculation. As @dyp first posted, `There does not seem to be a good reason for this inconsistency.` – Adrian Jan 11 '15 at 14:50
  • And even if `complete specializations are no longer "template classes/functions", they are are "real" classes/methods, and get to have real (linker-visible) symbols.` were true, this is full specialization based on the outer template parameter which is not specialized, so still shouldn't have any linker visible symbols. – Adrian Jan 11 '15 at 14:51

0 Answers0