Quick Q: Make C++ fail compilation on specific instantiation of template function

Quick Q: Delete its constructor

Recently on SO:

Make C++ fail compilation on specific instantiation of template function

Since foo is a complete specialization, it will always get compiled, and the static assert will always get called.

However, there’s an easier way:

template <>
Bar foo<Bar>(Bar val) = delete;

This will say that this specific version is deleted, and cannot be called.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.