Category : compile-time

I was reading the GCC documentation on C and C++ function attributes. In the description of the error and warning attributes, the documentation casually mentions the following "trick": error ("message") warning ("message") If the error or warning attribute is used on a function declaration and a call to such a function is not eliminated through ..

Read more

This is a simplified, reproducible version of my code: type_id.h template<typename> void type_id() {} typedef void(*type_id_t)(); c_sort.h (based on this answer) template<typename Array> constexpr void c_sort_impl(Array& array_) noexcept { using size_type = typename Array::size_type; size_type gap = array_.size(); bool swapped = false; while ((gap > size_type{ 1 }) or swapped) { if (gap > size_type{ ..

Read more

Consider these 2 examples Example 1 template<Type type> static BaseSomething* createSomething(); template<> BaseSomething* createSomething<Type::Something1>() { return Something1Creator.create(); } template<> BaseSomething* createSomething<Type::Something2>() { return Something2Creator.create(); } …. // other somethings Example2 template<Type type> static BaseSomething* createSomething() { if constexpr(type == Type::Something1) { return Something1Creator.create(); } else if constexpr(type == Type::Something2) { return Something2Creator.create(); } // Other ..

Read more

I created the constexpr version of the Curiously Recurring Template Pattern and all seem to work as expected, except the destructor who "under normal circumstances" should be marked as virtual. As I can understand, virtual is the vital enemy of constexpr. In my example I implemented two interfaces with no data-members. Is it correct in ..

Read more