mardi 5 septembre 2017

C++11: Variadic template deduction logic

I have the following construct:

template <class... Args>
class some_class
{
public:
    some_class() = default;
    some_class(Args...) = delete;
    ~some_class() = default;
};

template<>
class some_class<void>
{
public:
    some_class() = default;
    ~some_class() = default;
};

The reason for this is that I just want to allow the users to create objects using the default constructor, so for example:

some_class<int,float> b;

should work but

some_class<int,float> c(1,3.4);

should give me a compilation error.

At some point in time I also needed to create templates based on void hence, the specialization for void:

some_class<void> a;

But by mistake I have typed:

some_class<> d;

And suddenly my code stopped compiling and it gave me the error:

some_class<Args>::some_class(Args ...) [with Args = {}]’ cannot be 
overloaded
 some_class(Args...) = delete;

So here comes the question: I feel that I am wrong that I assume that some_class<> should be deduced to the void specialization... I just don't know why. Can please someone explain why some_class<> (ie: empty argument list) is different from some_class<void>? (A few lines from the standard will do :) )

http://ift.tt/2wAEBF6

Aucun commentaire:

Enregistrer un commentaire