C++Guns – RoboBlog

18.06.2021

C++ Guns: template Spezialisierung mit concepts

Filed under: Allgemein — Tags: — Thomas @ 12:06

Die requires Klausel ist echt toll!

#include <array>
#include <iostream>
 
template<typename ...Ts> 
requires (sizeof...(Ts) > 0)
void f(Ts...) {
    std::cout << "not empty\n";
}

template<typename ...Ts> 
requires (sizeof...(Ts) == 0)
void f(Ts...) {
    std::cout << "empty\n";
}

 
int main() {
    f('a', 1);  // Ts... expands to void f(char, int)
    f(0.1);     // Ts... expands to void f(double)
    f();     // Ts... expands to void f()
}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress