如何将一个适当做constexpr函数内的static_assert?例如: constexpr int do_something(int x)
{
static_assert(x > 0, "x must be > 0");
return x + 5;
}
这不是有效的C++代码11,因为constexpr函数只能包含一个return语句。我认为标准没有例外,尽管GC
我意识到这是一个人为的例子,但我想编译检查,以防止这种... class A {};
class B : public A {};
class C : public A {};
class D : public B, public C
{
BOOST_STATIC_ASSERT((is_base_of_once<A,D>::value))
};
我想有一个C++ 0x static_assert测试给定的结构类型是否为POD(以防止其他程序员无意中将其与新成员分开)。即, struct A // is a POD type
{
int x,y,z;
}
struct B // is not a POD type (has a nondefault ctor)
{
int x,y,z;
B(int _
我有几个模板设置结构,是否可以,在这些结构中使用静态断言? template<typename T, int N, (and so on...)>
struct Settings{
static const int n = N;
STATIC_ASSERT(n == 5);
typedef typename T GAGA;
}
感谢您的回复!