Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Static_assertExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppStatic_assertExample1/CppStatic_assertExample1.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ -Werror
SOURCES += main.cpp

 

 

 

 

 

./CppStatic_assertExample1/main.cpp

 

#include <functional>

template <class T>
struct MyClass
{
  typedef T This_t;
  MyClass()
  {
    static_assert(!std::is_same<This_t,int>(),"MyClass cannot have int type");
  }
};


int main()
{
  static_assert(1+1==2,"One plus one equals two");
  //static_assert(1==2,"One is not equal to two"); //Won't compile

  const MyClass<double> a;
  //MyClass<int> b; //Won't compile
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml