C++ Logo


Advanced search

Subject: Re: Can static_assert(false) be ignored in if constexpr?
From: Giuseppe D'Angelo (giuseppe.dangelo_at_[hidden])
Date: 2021-01-13 09:24:49

Il 13/01/21 15:23, Daniel Krügler via Std-Discussion ha scritto:
> A possible solution would be to write an always_false<T> class or
> variable template or concept and use it where you currently use
> "false". The relevant part is that the "false" value is dependent.

I wish there was an established solution for this.

So far, I've seen all sorts of ad-hoc solutions in different codebases:

  static_assert(!std::is_same_v<T, T>, ...);
  static_assert(sizeof(T) == 0, ...);
  static_assert(sizeof(T*) == 0, ...); // in case T might be incomplete
  []<bool f = false>() { static_assert(f, ...); }();
  static_assert(always_false<T>, ...); // with a suitable definition

All of them work, and yet, all of them look like dirty workarounds.


Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups