From: Gavin Lambert (boost_at_[hidden])
Date: 2021-08-05 23:55:45


On 5/08/2021 8:09 pm, Andrey Semashev wrote:
> On 8/5/21 4:18 AM, Gavin Lambert wrote:
>>> No, not really. Not only because needing is_constant_evaluated does
>>> not equate to needing type traits or metaprogramming, but because if
>>> the macro check says "no" then you've included <type_traits> for
>>> nothing.
>>
>> Yes, really.  That's the header in which std::is_constant_evaluated is
>> defined (as well as the feature macro you're wanting to check), so if
>> you're wanting to use it then you have to include the header anyway.
>>
>> There's not really any point in making the include itself conditional
>> (even if you could), except perhaps on something more generic (such as
>> "is C++11 or later", to detect cases when the header wouldn't exist).
>
> The point is reducing compile times. When all you need from
> <type_traits> is is_constant_evaluated, it is wasteful to include the
> header, especially if that component doesn't exist.

The probability that any real-world translation unit does not already
include <type_traits> is approximately zero. More than half the other
STL headers implicitly include it anyway. (Or at least some internal
equivalent.)