Skip to content

Commit

Permalink
Add a type-dependent false expression
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Bailey <[email protected]>
  • Loading branch information
danrbailey committed Mar 12, 2024
1 parent 7624bea commit 77a4243
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions openvdb/openvdb/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,26 @@ template<typename FromType, typename ToType> struct CopyConstness<const FromType
/// @endcond


////////////////////////////////////////

/// @brief A type-dependent expression that always evaluates to false.
/// This is used as a work-around for the much discussed problem of wanting to do:
/// if constexpr (expr) { }
/// else { static_assert(false); }
///
/// At present, C++ evaluates static_assert(false) regardless of the outcome of the
/// compile-time expression. By using a type-dependent expression, the static assert
/// is only evaluated during instantiation:
///
/// static_assert(openvdb::AlwaysFalseValue<T>);
///
/// This results in the desired outcome of generating a compile-time static assert
/// only if the first clause evaluates to false.

template<class>
inline constexpr bool AlwaysFalseValue = false;


////////////////////////////////////////


Expand Down

0 comments on commit 77a4243

Please sign in to comment.