Reputation: 21974
As far as I can tell the code below asserts the same thing in two different ways:
#include <type_traits>
template<class T, class U>
concept nothrow_assignable = requires(T a, U b)
{
requires noexcept(a = b);
};
template<class T>
void foo()
{
// new way
static_assert(nothrow_assignable<T, T>);
// old way
static_assert(std::is_nothrow_assignable_v<T, T>);
}
is there any reason to ever prefer the old way? The type_traits
header is 3K+ lines of code, and this particular trait ends up invoking a deep tree of other traits (the definition is surprisingly involved, checking if the type is an array, a reference, a pointer, a function, etc and each of those checks instantiates a few more) so I would prefer not to use it for the sake of keeping my compile times low. But at the same time I've noticed that there don't appear to be standard concepts for every standard type trait (I have to implement nothrow_assignable
myself) which seems like an obvious oversight so I'm wondering if there is a trade off here.
Upvotes: 0
Views: 228