@@ -877,6 +877,8 @@ namespace boost { namespace leaf {
877877
878878 // //////////////////////////////////////
879879
880+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
881+
880882 namespace leaf_detail
881883 {
882884 class e_unexpected_count
@@ -983,6 +985,8 @@ namespace boost { namespace leaf {
983985 }
984986 }
985987
988+ #endif
989+
986990 // //////////////////////////////////////
987991
988992 namespace leaf_detail
@@ -1113,6 +1117,8 @@ namespace boost { namespace leaf {
11131117 }
11141118 };
11151119
1120+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
1121+
11161122 template <class E >
11171123 inline void load_unexpected_count ( int err_id, E const & e ) noexcept
11181124 {
@@ -1140,6 +1146,8 @@ namespace boost { namespace leaf {
11401146 load_unexpected_info (err_id, e);
11411147 }
11421148
1149+ #endif
1150+
11431151 template <class E >
11441152 inline void slot<E>::deactivate( bool propagate_errors ) noexcept
11451153 {
@@ -1154,6 +1162,7 @@ namespace boost { namespace leaf {
11541162 prev_->err_id_ = err_id_;
11551163 }
11561164 }
1165+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
11571166 else
11581167 {
11591168 int c = tl_unexpected_enabled_counter ();
@@ -1162,6 +1171,7 @@ namespace boost { namespace leaf {
11621171 if ( E const * e = impl::has_value () )
11631172 no_expect_slot (err_id_, *e);
11641173 }
1174+ #endif
11651175 *top_ = prev_;
11661176 top_ = 0 ;
11671177 slot_base::deactivate ();
@@ -1174,13 +1184,15 @@ namespace boost { namespace leaf {
11741184 assert (err_id);
11751185 if ( slot<T> * p = tl_slot_ptr<T>() )
11761186 (void ) p->load (err_id, std::forward<E>(e));
1187+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
11771188 else
11781189 {
11791190 int c = tl_unexpected_enabled_counter ();
11801191 assert (c>=0 );
11811192 if ( c )
11821193 no_expect_slot (err_id, std::forward<E>(e));
11831194 }
1195+ #endif
11841196 return 0 ;
11851197 }
11861198
@@ -1970,6 +1982,10 @@ namespace boost { namespace leaf {
19701982 template <> struct does_not_participate_in_context_deduction <error_info>: std::true_type { };
19711983 template <> struct does_not_participate_in_context_deduction <std::error_code>: std::true_type { };
19721984 template <> struct does_not_participate_in_context_deduction <void >: std::true_type { };
1985+ #ifdef BOOST_LEAF_DISCARD_UNEXPECTED
1986+ template <> struct does_not_participate_in_context_deduction <e_unexpected_count>: std::true_type { };
1987+ template <> struct does_not_participate_in_context_deduction <e_unexpected_info>: std::true_type { };
1988+ #endif
19731989
19741990 template <class L >
19751991 struct transform_e_type_list_impl ;
@@ -2073,8 +2089,10 @@ namespace boost { namespace leaf {
20732089 using namespace leaf_detail ;
20742090 assert (!is_active ());
20752091 tuple_for_each<std::tuple_size<Tup>::value,Tup>::activate (tup_);
2092+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
20762093 if ( unexpected_requested<Tup>::value )
20772094 ++tl_unexpected_enabled_counter ();
2095+ #endif
20782096 thread_id_ = std::this_thread::get_id ();
20792097 is_active_ = true ;
20802098 }
@@ -2085,8 +2103,10 @@ namespace boost { namespace leaf {
20852103 assert (is_active ());
20862104 is_active_ = false ;
20872105 thread_id_ = std::thread::id ();
2106+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
20882107 if ( unexpected_requested<Tup>::value )
20892108 --tl_unexpected_enabled_counter ();
2109+ #endif
20902110 tuple_for_each<std::tuple_size<Tup>::value,Tup>::deactivate (tup_, propagate_errors);
20912111 }
20922112
@@ -2440,6 +2460,40 @@ namespace boost { namespace leaf {
24402460
24412461 // //////////////////////////////////////
24422462
2463+ #ifdef BOOST_LEAF_DISCARD_UNEXPECTED
2464+
2465+ class diagnostic_info : public error_info
2466+ {
2467+ public:
2468+
2469+ diagnostic_info ( error_info const & ei ) noexcept :
2470+ error_info (ei)
2471+ {
2472+ }
2473+
2474+ friend std::ostream & operator <<( std::ostream & os, diagnostic_info const & x )
2475+ {
2476+ return os << " leaf::diagnostic_info not available due to BOOST_LEAF_DISCARD_UNEXPECTED" << std::endl;
2477+ }
2478+ };
2479+
2480+ class verbose_diagnostic_info : public error_info
2481+ {
2482+ public:
2483+
2484+ verbose_diagnostic_info ( error_info const & ei ) noexcept :
2485+ error_info (ei)
2486+ {
2487+ }
2488+
2489+ friend std::ostream & operator <<( std::ostream & os, verbose_diagnostic_info const & x )
2490+ {
2491+ return os << " leaf::verbose_diagnostic_info not available due to BOOST_LEAF_DISCARD_UNEXPECTED" << std::endl;
2492+ }
2493+ };
2494+
2495+ #else
2496+
24432497 class diagnostic_info : public error_info
24442498 {
24452499 leaf_detail::e_unexpected_count const * e_uc_;
@@ -2496,6 +2550,8 @@ namespace boost { namespace leaf {
24962550 }
24972551 };
24982552
2553+ #endif
2554+
24992555 // //////////////////////////////////////
25002556
25012557 namespace leaf_detail
@@ -2784,6 +2840,30 @@ namespace boost { namespace leaf {
27842840 }
27852841 };
27862842
2843+ #ifdef BOOST_LEAF_DISCARD_UNEXPECTED
2844+
2845+ template <>
2846+ struct get_one_argument <diagnostic_info>
2847+ {
2848+ template <class SlotsTuple >
2849+ static diagnostic_info get ( SlotsTuple const & tup, error_info const & ei ) noexcept
2850+ {
2851+ return diagnostic_info (ei);
2852+ }
2853+ };
2854+
2855+ template <>
2856+ struct get_one_argument <verbose_diagnostic_info>
2857+ {
2858+ template <class SlotsTuple >
2859+ static verbose_diagnostic_info get ( SlotsTuple const & tup, error_info const & ei ) noexcept
2860+ {
2861+ return verbose_diagnostic_info (ei);
2862+ }
2863+ };
2864+
2865+ #else
2866+
27872867 template <>
27882868 struct get_one_argument <diagnostic_info>
27892869 {
@@ -2804,6 +2884,8 @@ namespace boost { namespace leaf {
28042884 }
28052885 };
28062886
2887+ #endif
2888+
28072889 template <>
28082890 struct get_one_argument <std::error_code>
28092891 {
@@ -3840,13 +3922,15 @@ namespace boost { namespace leaf {
38403922 if ( !s_->has_value (err_id) )
38413923 s_->load (err_id, std::move (e_));
38423924 }
3925+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
38433926 else
38443927 {
38453928 int c = tl_unexpected_enabled_counter ();
38463929 assert (c>=0 );
38473930 if ( c )
38483931 no_expect_slot (err_id, std::forward<E>(e_));
38493932 }
3933+ #endif
38503934 }
38513935 };
38523936
@@ -3925,13 +4009,15 @@ namespace boost { namespace leaf {
39254009 if ( !s_->has_value (err_id) )
39264010 s_->load (err_id, f_ ());
39274011 }
4012+ #ifndef BOOST_LEAF_DISCARD_UNEXPECTED
39284013 else
39294014 {
39304015 int c = tl_unexpected_enabled_counter ();
39314016 assert (c>=0 );
39324017 if ( c )
39334018 no_expect_slot (err_id, std::forward<E>(f_ ()));
39344019 }
4020+ #endif
39354021 }
39364022 };
39374023
0 commit comments