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

Save to:
Instapaper Pocket Readability

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

You must sign in or register to add a comment.

Comments (0)

There are currently no comments on this entry.