C++Guns – RoboBlog

10.05.2019

C++ Guns: C++20 class types in non-type template parameters

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

Mit C++20 und GCC9 wir können als Template Parameter nun auch einfach eigenen Typen angeben. Ohne uns mit Workarounds herumschlagen zu müssen.

Ein einfaches Beispiel sollte es verdeutlichen

struct MyType {
    int value;
};

template<MyType x>
auto func2() {
  return x.value;
} 

auto func3() {
    func2<MyType{1}>();
    constexpr MyType x{2};
    return func2<x>();
}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress