C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Thou shalt not... specify deducible template arguments?
From: Giuseppe D'Angelo (giuseppe.dangelo_at_[hidden])
Date: 2020-10-30 08:00:17


Hello,

Il 29/10/20 14:26, Jason McKesson via Std-Discussion ha scritto:
> The fact that a function is a template is not an implementation
> detail, nor are its template parameters*regardless* of their
> deducibility.

A very courteous reader of this list (thank you!) pointed me at
[algorithms.requirements] § 15, which says:

> https://eel.is/c++draft/algorithms.requirements#15

> The number and order of deducible template parameters for algorithm declarations are unspecified, except where explicitly stated otherwise.
> [Note 3: Consequently, an implementation can reject calls that specify an explicit template argument list. -- end note]

My initial "hunch" was therefore correct, but my examples quite wrong
(*). I somehow still think that this note could be applied to more
function templates than just the algorithms, though; users should call
functions and specify template arguments only if they must (e.g.
std::forward, std::make_unique, etc.), and not just because they can
(e.g. std::move).

(*) Correcting myself:

> std::sort<std::vector<int>::iterator>(v.begin(), v.end());

This is unspecified behaviour.

> std::min<double>(3.14, 1.23f);

This is instead always well defined because of [alg.min.max] § 4, which
allows it:

> https://eel.is/c++draft/algorithms#alg.min.max-4
> Remarks: An invocation may explicitly specify an argument for the template parameter T of the overloads in namespace std.

Thanks for reading,

-- 
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups