C++Guns – RoboBlog

30.10.2018

C++ Guns: disable function with concepts without SFINAE std::enable_if

Filed under: Allgemein — Tags: — Thomas @ 21:10

std::enable_if is dead; long live concepts!

Man beachte, dass die Requires clause NACH dem Funktionskopf kommen kann.

#include <type_traits>

template<typename T>
void func(T) requires std::is_integral_v<T> {
}

auto func2() {
    // error: cannot call function 'void func(T) requires  is_integral_v<T> [with T = double]'
    // constraints not satisfied  'is_integral_v<T>' evaluated to false
   func(2.0); // Nope
}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress