From 68fabb1a8ec6b734e1493fa8836f64886fc3edc1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 11 May 2026 21:23:29 +0300 Subject: [PATCH] Do not throw an exception when hashing valueless std::variant values --- include/boost/container_hash/hash.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/container_hash/hash.hpp b/include/boost/container_hash/hash.hpp index 1fe3f2f..7eb2755 100644 --- a/include/boost/container_hash/hash.hpp +++ b/include/boost/container_hash/hash.hpp @@ -455,7 +455,11 @@ namespace boost std::size_t seed = 0; hash_combine( seed, v.index() ); - std::visit( [&seed](auto&& x) { hash_combine(seed, x); }, v ); + + if( !v.valueless_by_exception() ) + { + std::visit( [&seed](auto&& x) { hash_combine(seed, x); }, v ); + } return seed; }