int f();
static_assert(f(), "f"); static_assert(true, "true is not false");
static_assert(false, "false is false");
void g() {
static_assert(false, "false is false"); }
class C {
static_assert(false, "false is false"); };
template<int N> struct T {
static_assert(N == 2, "N is not 2!"); };
T<1> t1; T<2> t2;
template<typename T> struct S {
static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); };
S<char> s1; S<int> s2;
static_assert(false, L"\xFFFFFFFF"); static_assert(false, u"\U000317FF");
static_assert(false, u8"Ω"); static_assert(false, L"\u1234"); static_assert(false, L"\x1ff" "0\x123" "fx\xfffff" "goop");
static_assert(false, R"(a
\tb
c
)");
static_assert(false, "\u0080\u0081\u0082\u0083\u0099\u009A\u009B\u009C\u009D\u009E\u009F");
static_assert(false, "\u200Eabc\u200Fdef\u200Fgh");
static_assert(false, "🏳️🌈 🏴 🇪🇺");
template<typename T> struct AlwaysFails {
static_assert(false, ""); };
AlwaysFails<int> alwaysFails;
template<typename T> struct StaticAssertProtected {
static_assert(__is_literal(T), ""); static constexpr T t = {}; };
struct X { ~X(); };
StaticAssertProtected<int> sap1;
StaticAssertProtected<X> sap2;
static_assert(true); static_assert(false);
template<typename T> struct first_trait {
static const bool value = false;
};
template<>
struct first_trait<X> {
static const bool value = true;
};
template<typename T> struct second_trait {
static const bool value = false;
};
static_assert(first_trait<X>::value && second_trait<X>::value, "message");
namespace std {
template <class Tp, Tp v>
struct integral_constant {
static const Tp value = v;
typedef Tp value_type;
typedef integral_constant type;
constexpr operator value_type() const noexcept { return value; }
constexpr value_type operator()() const noexcept { return value; }
};
template <class Tp, Tp v>
const Tp integral_constant<Tp, v>::value;
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
template <class Tp>
struct is_const : public false_type {};
template <class Tp>
struct is_const<Tp const> : public true_type {};
template <typename T, typename U>
struct is_same {
static const bool value = false;
};
template <typename T>
struct is_same<T, T> {
static const bool value = true;
};
}
struct ExampleTypes {
explicit ExampleTypes(int);
using T = int;
using U = float;
};
static_assert(std::is_same<ExampleTypes::T, ExampleTypes::U>::value, "message");
static_assert(std::is_const<ExampleTypes::T>::value, "message");
static_assert(!std::is_const<const ExampleTypes::T>::value, "message");
static_assert(!(std::is_const<const ExampleTypes::T>::value), "message");
static_assert(std::is_const<const ExampleTypes::T>::value == false, "message");
static_assert(!(std::is_const<const ExampleTypes::T>::value == true), "message");
static_assert(std::is_const<ExampleTypes::T>(), "message");
static_assert(!(std::is_const<const ExampleTypes::T>()()), "message");
static_assert(std::is_same<decltype(std::is_const<const ExampleTypes::T>()), int>::value, "message");
static_assert(std::is_const<decltype(ExampleTypes::T(3))>::value, "message");
static_assert(std::is_const<decltype(ExampleTypes::T())>::value, "message");
static_assert(std::is_const<decltype(ExampleTypes(3))>::value, "message");
struct BI_tag {};
struct RAI_tag : BI_tag {};
struct MyIterator {
using tag = BI_tag;
};
struct MyContainer {
using iterator = MyIterator;
};
template <class Container>
void foo() {
static_assert(std::is_same<RAI_tag, typename Container::iterator::tag>::value, "message");
}
template void foo<MyContainer>();
namespace ns {
template <typename T, int v>
struct NestedTemplates1 {
struct NestedTemplates2 {
template <typename U>
struct NestedTemplates3 : public std::is_same<T, U> {};
};
};
}
template <typename T, typename U, int a>
void foo2() {
static_assert(::ns::NestedTemplates1<T, a>::NestedTemplates2::template NestedTemplates3<U>::value, "message");
}
template void foo2<int, float, 3>();
template <class T>
void foo3(T t) {
static_assert(std::is_const<T>::value, "message");
static_assert(std::is_const<decltype(t)>::value, "message");
}
void callFoo3() {
foo3([]() {});
}
template <class T>
void foo4(T t) {
static_assert(std::is_const<typename T::iterator>::value, "message");
}
void callFoo4() { foo4(42); }
static_assert(42, "message");
static_assert(42.0, "message"); constexpr int *p = 0;
static_assert(p, "message");
struct NotBool {
} notBool;
constexpr NotBool constexprNotBool;
static_assert(notBool, "message"); static_assert(constexprNotBool, "message");
static_assert(1 , "")