Back to slide -- Keyboard shortcut: 'u'                      static-assert/p5.cc - Illustration of of type functions in a number static assertions - all of which hold.Lecture 6 - slide 31 : 40
Program 1

// Compiles without errors, meaning that all the static_asserts hold.

#include <iostream>
#include <string>
#include <type_traits>

class D {};

class E{
  public: 
    virtual void vf(){};
};

int main(){
  int a;
  int &b = a;
  int *c = &a;
  D d;
  E *ep;

  std::remove_pointer<decltype(ep)>::type f;   // Corresponds to     E f;
  f.vf();   // OK, because the type of f is E.

  static_assert(std::is_integral<decltype(a)>::value, "type of a is expected to be integral");

  static_assert(std::is_fundamental<decltype(a)>::value, "type of a is expected to be a fundamental type");

  static_assert(std::is_reference<decltype(b)>::value, "type of b is expected to be a reference");

  static_assert(std::is_lvalue_reference<decltype(b)>::value, "type of b is expected to be a lvalue reference");

  static_assert(!std::is_rvalue_reference<decltype(b)>::value, "type of b is NOT expected to be a rvalue reference");

  static_assert(std::is_pointer<decltype(c)>::value, "type of c is expected to be a pointer");

  static_assert(std::is_class<decltype(d)>::value, "type of d is expected to be a class");

  static_assert(std::is_polymorphic<E>::value, "E is expected to be polymorphic - it has a virtual function");

  static_assert(std::is_polymorphic<std::remove_pointer<decltype(ep)>::type>::value, 
                "ep (without ptr) is expected to be polymorphic");

}