Skip to content

Commit d68cc12

Browse files
committed
BOOST_LEAF_DISCARD_UNEXPECTED
1 parent a6abe5a commit d68cc12

File tree

14 files changed

+218
-4
lines changed

14 files changed

+218
-4
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ script:
252252
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
253253
- ../../b2 variant=debug test toolset=$TOOLSET cxxstd=$CXXSTD
254254
- ../../b2 variant=release test toolset=$TOOLSET cxxstd=$CXXSTD
255+
- ../../b2 variant=debug-discard-unexpected test toolset=$TOOLSET cxxstd=$CXXSTD
256+
- ../../b2 variant=release-discard-unexpected test toolset=$TOOLSET cxxstd=$CXXSTD
255257
# - cd bld/debug && meson test
256258

257259
notifications:

.vscode/tasks.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
"command": "${workspaceRoot}/.vscode/msvc.bat && cd ${workspaceRoot}/bld/debug && meson test"
2424
}
2525
},
26+
{
27+
"label": "Run all unit tests (BOOST_LEAF_DISCARD_UNEXPECTED)",
28+
"type": "shell",
29+
"command": "cd ${workspaceRoot}/bld/debug_discard_unexpected && meson test",
30+
"problemMatcher": { "base": "$gcc", "fileLocation": ["relative","${workspaceRoot}/bld/debug_discard_unexpected"] },
31+
"windows": {
32+
"command": "${workspaceRoot}/.vscode/msvc.bat && cd ${workspaceRoot}/bld/debug_discard_unexpected && meson test"
33+
}
34+
},
2635
{
2736
"label": "accumulate_basic_test",
2837
"type": "shell",

include/boost/leaf/all.hpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

include/boost/leaf/context.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ namespace boost { namespace leaf {
129129
template <> struct does_not_participate_in_context_deduction<error_info>: std::true_type { };
130130
template <> struct does_not_participate_in_context_deduction<std::error_code>: std::true_type { };
131131
template <> struct does_not_participate_in_context_deduction<void>: std::true_type { };
132+
#ifdef BOOST_LEAF_DISCARD_UNEXPECTED
133+
template <> struct does_not_participate_in_context_deduction<e_unexpected_count>: std::true_type { };
134+
template <> struct does_not_participate_in_context_deduction<e_unexpected_info>: std::true_type { };
135+
#endif
132136

133137
template <class L>
134138
struct transform_e_type_list_impl;
@@ -232,8 +236,10 @@ namespace boost { namespace leaf {
232236
using namespace leaf_detail;
233237
assert(!is_active());
234238
tuple_for_each<std::tuple_size<Tup>::value,Tup>::activate(tup_);
239+
#ifndef BOOST_LEAF_DISCARD_UNEXPECTED
235240
if( unexpected_requested<Tup>::value )
236241
++tl_unexpected_enabled_counter();
242+
#endif
237243
thread_id_ = std::this_thread::get_id();
238244
is_active_ = true;
239245
}
@@ -244,8 +250,10 @@ namespace boost { namespace leaf {
244250
assert(is_active());
245251
is_active_ = false;
246252
thread_id_ = std::thread::id();
253+
#ifndef BOOST_LEAF_DISCARD_UNEXPECTED
247254
if( unexpected_requested<Tup>::value )
248255
--tl_unexpected_enabled_counter();
256+
#endif
249257
tuple_for_each<std::tuple_size<Tup>::value,Tup>::deactivate(tup_, propagate_errors);
250258
}
251259

include/boost/leaf/detail/handle.hpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,40 @@ namespace boost { namespace leaf {
112112

113113
////////////////////////////////////////
114114

115+
#ifdef BOOST_LEAF_DISCARD_UNEXPECTED
116+
117+
class diagnostic_info: public error_info
118+
{
119+
public:
120+
121+
diagnostic_info( error_info const & ei ) noexcept:
122+
error_info(ei)
123+
{
124+
}
125+
126+
friend std::ostream & operator<<( std::ostream & os, diagnostic_info const & x )
127+
{
128+
return os << "leaf::diagnostic_info not available due to BOOST_LEAF_DISCARD_UNEXPECTED" << std::endl;
129+
}
130+
};
131+
132+
class verbose_diagnostic_info: public error_info
133+
{
134+
public:
135+
136+
verbose_diagnostic_info( error_info const & ei ) noexcept:
137+
error_info(ei)
138+
{
139+
}
140+
141+
friend std::ostream & operator<<( std::ostream & os, verbose_diagnostic_info const & x )
142+
{
143+
return os << "leaf::verbose_diagnostic_info not available due to BOOST_LEAF_DISCARD_UNEXPECTED" << std::endl;
144+
}
145+
};
146+
147+
#else
148+
115149
class diagnostic_info: public error_info
116150
{
117151
leaf_detail::e_unexpected_count const * e_uc_;
@@ -168,6 +202,8 @@ namespace boost { namespace leaf {
168202
}
169203
};
170204

205+
#endif
206+
171207
////////////////////////////////////////
172208

173209
namespace leaf_detail
@@ -456,6 +492,30 @@ namespace boost { namespace leaf {
456492
}
457493
};
458494

495+
#ifdef BOOST_LEAF_DISCARD_UNEXPECTED
496+
497+
template <>
498+
struct get_one_argument<diagnostic_info>
499+
{
500+
template <class SlotsTuple>
501+
static diagnostic_info get( SlotsTuple const & tup, error_info const & ei ) noexcept
502+
{
503+
return diagnostic_info(ei);
504+
}
505+
};
506+
507+
template <>
508+
struct get_one_argument<verbose_diagnostic_info>
509+
{
510+
template <class SlotsTuple>
511+
static verbose_diagnostic_info get( SlotsTuple const & tup, error_info const & ei ) noexcept
512+
{
513+
return verbose_diagnostic_info(ei);
514+
}
515+
};
516+
517+
#else
518+
459519
template <>
460520
struct get_one_argument<diagnostic_info>
461521
{
@@ -476,6 +536,8 @@ namespace boost { namespace leaf {
476536
}
477537
};
478538

539+
#endif
540+
479541
template <>
480542
struct get_one_argument<std::error_code>
481543
{

0 commit comments

Comments
 (0)