1

I post here about checking variadic templates parameters for uniqueness check variadic templates parameters for uniqueness.

My question: Why following code isn't compiled? Is It bug compiler or standard is not allowedd?

#include <iostream>


template< class ... > struct pack{};
template< class  > struct id{};
template< class  > struct base_all;
template< class ...T>
struct base_all< pack<T...> > : id<T> ... {using type = int;}; // <-- error with `int`, `char`, `int`  parameters.

template< class ...T>
struct is_unique
{
    template< class P,  std::size_t = sizeof(base_all<P>)  >
    struct check;

    template< class P >
    static constexpr bool test( check< P > * ) noexcept { return true ;}

    template< class P >
    static constexpr bool test( ... ) noexcept{ return false; }

    static constexpr bool value = test< pack<T...> >( nullptr );
};

int main()
{
    constexpr bool b = is_unique<int, float, double>::value;

    constexpr bool c = is_unique<int, char, int >::value; //<--- error 

    std::cout << std::boolalpha << "b = " << b << "\nc = " << c << std::endl;
}

error compiler gcc 4.8.1:

is_unique_args.cpp:16:42:   required by substitution of ‘template<class P> static constexpr bool is_unique<T>::test(is_unique<T>::check<P>*) [with P = P; T = {int, char, int}] [with P = pack<int, char, int>]’
Community
  • 1
  • 1
Khurshid Normuradov
  • 1,564
  • 1
  • 13
  • 20
  • SFINAE only considers the immediate context, basically everything that's "visible" (that you can see) at the function site, and what's inside `using`-aliases. Invalid base members do not count, that's an indirect error. – Xeo Sep 27 '13 at 06:54
  • 2
    @g-makulik. It's not duplicate, It's continuous... )) – Khurshid Normuradov Sep 27 '13 at 07:02
  • OK! I see you seem to have some progress (nevertheless I'd have edited and updated the original question, and maybe started a bounty). I'm not really sure if this is of any help for you, I've been asking a question recently how to process a `std::tuple` parameters pack to do some calculations at compile time: [Creating an array initializer from a tuple or variadic template parameters](http://stackoverflow.com/questions/18251815/creating-an-array-initializer-from-a-tuple-or-variadic-template-parameters). May be this can give you a direction. – πάντα ῥεῖ Sep 27 '13 at 17:50

1 Answers1

1

I compiled your example like this :

g++ -Wall -Wextra -std=c++11 -rdynamic -pedantic garbage.cpp

and got different error :

garbage.cpp: In instantiation of ‘struct base_all<pack<int, char, int> >’:
garbage.cpp:17:27:   required by substitution of ‘template<class P> static constexpr bool is_unique::test(is_unique<T>::check<P>*) [with P = P; T = {int, char, int}] [with P = pack<int, char, int>]’
garbage.cpp:22:63:   required from ‘constexpr const bool is_unique<int, char, int>::value’
garbage.cpp:29:52:   required from here
garbage.cpp:8:8: error: duplicate base type ‘id<int>’ invalid

To highlight the error once again :

duplicate base type ‘id’ invalid

It is very clear what it means. c++ forbids having more base classes of the same type. So, this is forbidden by the standard :

struct A
{};
struct B : A, A
{};

And that is what you tried to do above.

BЈовић
  • 62,405
  • 41
  • 173
  • 273