Skip to content

Commit 1f7ed9a

Browse files
committed
Add a type-dependent false expression
1 parent e3ac780 commit 1f7ed9a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

openvdb/openvdb/Types.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,26 @@ template<typename FromType, typename ToType> struct CopyConstness<const FromType
446446
/// @endcond
447447

448448

449+
////////////////////////////////////////
450+
451+
/// @brief A type-dependent expression that always evaluates to false.
452+
/// This is used as a work-around for the much discussed problem of wanting to do:
453+
/// if constexpr (expr) { }
454+
/// else { static_assert(false); }
455+
///
456+
/// At present, C++ evaluates static_assert(false) regardless of the outcome of the
457+
/// compile-time expression. By using a type-dependent expression, the static assert
458+
/// is only evaluated during instantiation:
459+
///
460+
/// static_assert(openvdb::AlwaysFalseValue<T>);
461+
///
462+
/// This results in the desired outcome of generating a compile-time static assert
463+
/// only if the first clause evaluates to false.
464+
465+
template<class>
466+
inline constexpr bool AlwaysFalseValue = false;
467+
468+
449469
////////////////////////////////////////
450470

451471

0 commit comments

Comments
 (0)