@@ -119,21 +119,6 @@ namespace Aws
119
119
} // namespace VariantDebug
120
120
#endif /* defined(AWS_CRT_ENABLE_VARIANT_DEBUG) */
121
121
122
- template <bool > class DefaultConstructibleVariant ;
123
-
124
- template <> class DefaultConstructibleVariant <true >
125
- {
126
- public:
127
- explicit DefaultConstructibleVariant (int ) {}
128
- DefaultConstructibleVariant () = default ;
129
- };
130
- template <> class DefaultConstructibleVariant <false >
131
- {
132
- public:
133
- explicit DefaultConstructibleVariant (int ) {}
134
- DefaultConstructibleVariant () = delete ;
135
- };
136
-
137
122
/* Depending on the Variant types, this struct either deletes special move members or defaults them. */
138
123
template <bool > class MovableVariant ;
139
124
@@ -199,6 +184,9 @@ namespace Aws
199
184
static constexpr bool isFirstAlternativeNothrowDefaultConstructible =
200
185
std::is_nothrow_default_constructible<FirstAlternative>::value;
201
186
187
+ static constexpr bool isFirstAlternativeDefaultConstructible =
188
+ std::is_nothrow_constructible<FirstAlternative>::value;
189
+
202
190
using IndexT = VariantDetail::Index::VariantIndex;
203
191
static constexpr std::size_t AlternativeCount = sizeof ...(Ts);
204
192
@@ -672,9 +660,7 @@ namespace Aws
672
660
* @tparam Ts Types of the variant value.
673
661
*/
674
662
template <typename ... Ts>
675
- class Variant : public VariantDetail ::DefaultConstructibleVariant<
676
- VariantDetail::VariantImpl<Ts...>::isFirstAlternativeNothrowDefaultConstructible>,
677
- public VariantDetail::MovableVariant<Conjunction<std::is_move_constructible<Ts>...>::value>,
663
+ class Variant : public VariantDetail ::MovableVariant<Conjunction<std::is_move_constructible<Ts>...>::value>,
678
664
public VariantDetail::CopyableVariant<Conjunction<std::is_copy_constructible<Ts>...>::value>
679
665
{
680
666
/* Copyability and Movability depend only on constructors (copy and move correspondingly) of the
@@ -697,26 +683,30 @@ namespace Aws
697
683
using IndexT = VariantDetail::Index::VariantIndex;
698
684
static constexpr std::size_t AlternativeCount = sizeof ...(Ts);
699
685
700
- Variant () = default ;
686
+ template <
687
+ typename T = typename VariantDetail::VariantImpl<Ts...>::FirstAlternative,
688
+ typename std::enable_if<std::is_default_constructible<T>::value, bool >::type = true >
689
+ Variant () noexcept (isFirstAlternativeNothrowDefaultConstructible)
690
+ {
691
+ }
692
+
693
+ template <
694
+ typename T = typename VariantDetail::VariantImpl<Ts...>::FirstAlternative,
695
+ typename std::enable_if<!std::is_default_constructible<T>::value, bool >::type = true >
696
+ Variant () = delete ;
701
697
702
- template <typename T, EnableIfOtherIsThisVariantAlternative<T> = 1 >
703
- Variant (const T &val)
704
- : VariantDetail::DefaultConstructibleVariant<isFirstAlternativeNothrowDefaultConstructible>(1 ),
705
- m_variant (val)
698
+ template <typename T, EnableIfOtherIsThisVariantAlternative<T> = 1 > Variant (const T &val) : m_variant(val)
706
699
{
707
700
}
708
701
709
702
template <typename T, EnableIfOtherIsThisVariantAlternative<T> = 1 >
710
- Variant (T &&val)
711
- : VariantDetail::DefaultConstructibleVariant<isFirstAlternativeNothrowDefaultConstructible>(1 ),
712
- m_variant (std::forward<T>(val))
703
+ Variant (T &&val) : m_variant(std::forward<T>(val))
713
704
{
714
705
}
715
706
716
707
template <typename T, typename ... Args>
717
708
explicit Variant (Aws::Crt::InPlaceTypeT<T> ipt, Args &&...args)
718
- : VariantDetail::DefaultConstructibleVariant<isFirstAlternativeNothrowDefaultConstructible>(1 ),
719
- m_variant(ipt, std::forward<Args>(args)...)
709
+ : m_variant(ipt, std::forward<Args>(args)...)
720
710
{
721
711
}
722
712
0 commit comments