An assertion statement that is verified at the compilation time. A feature of C++0x/C++11, supported by gcc since 4.3.

learn more… | top users | synonyms

6
votes
2answers
161 views

Force deriving from a class virtually

We have a special framework for interfaces in our project, and part of the requirements is that classes which represent an interface may only be used as virtual base classes, not as non-virtual ones. ...
1
vote
1answer
98 views

C++11 static assert for equality comparable type?

How to static_assert a template type is EqualityComparable concept in C++11?
0
votes
2answers
39 views

How to C++11 static_assert for type constraint?

How can I make static_assert for specific type constraint? Currently I want to make my template only for unsigned int type, but not signed int type. Or, just only for integral type, or specific type ...
2
votes
2answers
105 views

Static assertions and SFINAE

Consider this: template <typename T> struct hash { static_assert(false,"Not implemented."); }; struct unhashable {}; template <typename T> auto test(const T &t) -> ...
11
votes
6answers
4k views

BOOST_STATIC_ASSERT without boost

Since boost is forbidden in a company I work for I need to implement its functionality in pure C++. I've looked into boost sources but they seem to be too complex to understand, at least for me. I ...
1
vote
2answers
115 views

Using static_assert() to provide better compile-time errors (than the compilers)

Yesterday it took me ages to come to grips with a compile-time error caused by calling a const member function from a non-const object as in this example: // my utility header template<typename ...
14
votes
4answers
6k views

Static assert in C

What's the best way to achieve compile time static asserts in C (not C++), with particular emphasis on GCC?
10
votes
8answers
9k views

Does GCC have a built-in compile time assert?

Our existing compile-time assert implementation is based on negative array index, and it provides poor diagnostic output on GCC. C++0x's static_assert is a very nice feature, and the diagnostic output ...
0
votes
1answer
148 views

/boost/lockfree/queue.hpp: error: static assertion failed: (boost::has_trivial_destructor<T>::value)

I'm trying to substitute boost::lockfree::queue for std::queue in this file https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp I've added #include ...
3
votes
1answer
87 views

Comparing static field pointers at compile time

I have a class B deriving from class A. A declares a static field f, and B might declare a similar field of the same name. The following does not work: struct A { static int f; }; struct B : A { ...
-2
votes
1answer
46 views

Compilation warning for Objects that contain non Copyable objects are unreadable

I've asked a similiar question before but now I'd like to be more specific. The problem I face is that I have an object that contains a non copyable object and when someone wants to use my interface ...
3
votes
4answers
89 views

Determine if same pointers are passed to a macro

There are set of macros, for debugging, logging, stack-trace displaying etc. One of them is like: #define ASSERT_IF_NULL_2(_ptr1, _ptr2) \ ASSERT(_ptr1); \ ASSERT(_ptr2); This is over ...
0
votes
2answers
96 views

C++11 is there a way to test method access level statically?

C++11 adds lots of new class templates which allow to test type traits statically, i.e. detect problems at compile time. I'm writing a test for a class and I need to make sure a given method is ...
1
vote
3answers
154 views

static_assert fails compilation even though template function is called nowhere

I use g++ 4.6.3, (currently default package for ubuntu 12.04) with the flag c++0x, and I stumble across this: template <typename T> inline T getValue(AnObject&) { static_assert(false , ...
0
votes
3answers
103 views

How to do static_assert with macros?

I have tried to use this suggestion to do a static assert, but I do not get a compilation error if I use it within a method of a template. The example follows : #include <iostream> #define ...

1 2 3 4 5
15 30 50 per page