Skip to content

Instantly share code, notes, and snippets.

@shoooe
Last active May 9, 2021 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoooe/55fbfdba31ca70c77a2e to your computer and use it in GitHub Desktop.
Save shoooe/55fbfdba31ca70c77a2e to your computer and use it in GitHub Desktop.
The asymmetries of C++

The asymmetries of C++

This is lighthearted collection of asymmetries of the C++ language. This is not, in any way, intended as a critic.


Partial specialization is allowed for class templates but not for function templates

§14.5.5 [temp.class.spec] describes the semantic and syntax for class template partial specialization such as, given:

template<typename T, std::size_t I> class X {};

the following are examples of partial specializations:

template<typename T> class X<T, 9> {};
template<typename T, std::size_t I> class X<T*, I> {};
template<std::size_t I> class X<int, I> {};

The same does not hold true for function templates. For example, the following is not valid syntax:

template<typename T, typename S> void func(T, S) {}
template<typename S> void func<int, S>(int, S) {}

For more informations you can read this great SO question.

Notes

  1. All standard quotes refer to draft N4296 which is publicly available here.
  2. Special thanks go to the folks at Lounge<C++>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment