C++ Logo

std-proposals

Advanced search

[std-proposals] Extending the usage of final: trying to make compiler optimize more aggressively and trying to make the language have a proper way to represent customization point objects (CPO).

From: Bingzhi <bingzhi2025_at_[hidden]>
Date: Mon, 10 Aug 2026 17:41:51 +0800 (CST)
template <class T> constexpr bool integer_like_v = integral<T>;
template <> constexpr bool integer_like_v<bool> = false;
template <> constexpr bool integer_like_v<max_size_type> = true;
final template <> constexpr bool integer_like_v<max_diff_type> = true;

template <> constexpr bool integer_like_v<__max_size_type> = true; // must be error

Even more, final can be used to end template overloads and regular overloads.

namespace ranges {
template <class T, class U> constexpr void swap(T&& t, U&& u);
template <class T, size_t N> constexpr void swap(T (&t)[N], T (&u)[N]);
// ...
final template <class T> constexpr void swap(T& t, T& u);

template <class T> constexpr void swap(T&& t, T&& u); // must be error
constexpr void swap(integral auto& t, integral auto& u); // must be error

constexpr void swap(int& t, int& u);
final constexpr void swap(short& t, short& u);
constexpr void swap(long& t, long& u); // must be error
}

final constexpr uint64_t gcd(uint64_t, uint64_t) noexcept;
//constexpr uint32_t gcd(uint32_t, uint32_t) noexcept; // must be error

Received on 2026-08-10 09:41:58