Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- // partial template specialization
- template <class T>
- struct A {
- void whoami() { std::cout << "A" << std::endl; }
- };
- template <class T>
- struct A<T*> {
- void whoami() { std::cout << "A*" << std::endl; }
- };
- // constexpr if
- template <class T>
- struct B {
- void whoami() {
- if constexpr (!std::is_pointer<T>()) {
- std::cout << "B" << std::endl;
- } else {
- std::cout << "B*" << std::endl;
- }
- }
- };
- int main()
- {
- A<int> a0;
- a0.whoami();
- A<int*> a1;
- a1.whoami();
- B<int> b0;
- b0.whoami();
- B<int*> b1;
- b1.whoami();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement