Skip to content

Commit c5f7cf5

Browse files
committed
Fix to only exclude hash<nonstd::monostate>, not hash<nonstd::variant> when variant_CONFIG_MONOSTATE is defined
Note: currently one cannot (yet) do `-Dvariant_CONFIG_MONOSTATE=nonstd::monostate` to get the default behaviour. Same holds for `-Dvariant_CONFIG_BAD_VARIANT_ACCESS=nonstd::bad_variant_access`.
1 parent da9b8ca commit c5f7cf5

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

include/nonstd/variant.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,11 @@ class variant;
12131213
// 19.7.8 Class monostate
12141214

12151215
#ifdef variant_CONFIG_MONOSTATE
1216+
12161217
using variant_CONFIG_MONOSTATE;
1218+
12171219
#else
1220+
12181221
class monostate{};
12191222

12201223
// 19.7.9 monostate relational operators
@@ -1224,7 +1227,8 @@ inline variant_constexpr bool operator<=( monostate, monostate ) variant_noexcep
12241227
inline variant_constexpr bool operator>=( monostate, monostate ) variant_noexcept { return true; }
12251228
inline variant_constexpr bool operator==( monostate, monostate ) variant_noexcept { return true; }
12261229
inline variant_constexpr bool operator!=( monostate, monostate ) variant_noexcept { return false; }
1227-
#endif
1230+
1231+
#endif // variant_CONFIG_MONOSTATE
12281232

12291233
// 19.7.4 variant helper classes
12301234

@@ -1298,7 +1302,7 @@ class variant_nodiscard bad_variant_access : public std::exception
12981302
return "bad variant access";
12991303
}
13001304
};
1301-
#endif
1305+
#endif // variant_CONFIG_BAD_VARIANT_ACCESS
13021306

13031307
#endif // variant_CONFIG_NO_EXCEPTIONS
13041308

@@ -2705,12 +2709,14 @@ using namespace variants;
27052709

27062710
} // namespace nonstd
27072711

2708-
#if ! defined (variant_CONFIG_MONOSTATE) && variant_CPP11_OR_GREATER
2712+
#if variant_CPP11_OR_GREATER
27092713

27102714
// 19.7.12 Hash support
27112715

27122716
namespace std {
27132717

2718+
#ifndef variant_CONFIG_MONOSTATE
2719+
27142720
template<>
27152721
struct hash< nonstd::monostate >
27162722
{
@@ -2720,6 +2726,8 @@ struct hash< nonstd::monostate >
27202726
}
27212727
};
27222728

2729+
#endif // variant_CONFIG_MONOSTATE
2730+
27232731
template< class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13, class T14, class T15 >
27242732
struct hash< nonstd::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >
27252733
{
@@ -2753,7 +2761,7 @@ struct hash< nonstd::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T
27532761

27542762
} //namespace std
27552763

2756-
#endif // ! defined (variant_CONFIG_MONOSTATE) && variant_CPP11_OR_GREATER
2764+
#endif // variant_CPP11_OR_GREATER
27572765

27582766
#if variant_BETWEEN( variant_COMPILER_MSVC_VER, 1300, 1900 )
27592767
# pragma warning( pop )

template/variant.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,11 @@ class variant;
10881088
// 19.7.8 Class monostate
10891089

10901090
#ifdef variant_CONFIG_MONOSTATE
1091+
10911092
using variant_CONFIG_MONOSTATE;
1093+
10921094
#else
1095+
10931096
class monostate{};
10941097

10951098
// 19.7.9 monostate relational operators
@@ -1099,6 +1102,7 @@ inline variant_constexpr bool operator<=( monostate, monostate ) variant_noexcep
10991102
inline variant_constexpr bool operator>=( monostate, monostate ) variant_noexcept { return true; }
11001103
inline variant_constexpr bool operator==( monostate, monostate ) variant_noexcept { return true; }
11011104
inline variant_constexpr bool operator!=( monostate, monostate ) variant_noexcept { return false; }
1105+
11021106
#endif // variant_CONFIG_MONOSTATE
11031107

11041108
// 19.7.4 variant helper classes
@@ -2050,12 +2054,14 @@ using namespace variants;
20502054

20512055
} // namespace nonstd
20522056

2053-
#if ! defined (variant_CONFIG_MONOSTATE) && variant_CPP11_OR_GREATER
2057+
#if variant_CPP11_OR_GREATER
20542058

20552059
// 19.7.12 Hash support
20562060

20572061
namespace std {
20582062

2063+
#ifndef variant_CONFIG_MONOSTATE
2064+
20592065
template<>
20602066
struct hash< nonstd::monostate >
20612067
{
@@ -2065,6 +2071,8 @@ struct hash< nonstd::monostate >
20652071
}
20662072
};
20672073

2074+
#endif // variant_CONFIG_MONOSTATE
2075+
20682076
template< {{TplParamsList}} >
20692077
struct hash< nonstd::variant<{{TplArgsList}}> >
20702078
{
@@ -2084,7 +2092,7 @@ struct hash< nonstd::variant<{{TplArgsList}}> >
20842092

20852093
} //namespace std
20862094

2087-
#endif // ! defined (variant_CONFIG_MONOSTATE) && variant_CPP11_OR_GREATER
2095+
#endif // variant_CPP11_OR_GREATER
20882096

20892097
#if variant_BETWEEN( variant_COMPILER_MSVC_VER, 1300, 1900 )
20902098
# pragma warning( pop )

0 commit comments

Comments
 (0)