Skip to content

Commit 1bc0829

Browse files
committed
Update documentation
1 parent 2547921 commit 1bc0829

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

doc/system/changes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ https://www.boost.org/LICENSE_1_0.txt
1212

1313
* Added support for `result<U&, E>`.
1414
* Added `operator|` for `result`.
15+
* Added `operator&` for `result`.
1516
1617
## Changes in Boost 1.81
1718

doc/system/reference.adoc

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,16 @@ template<class T, class E, class F, class R = ...> R operator|( result<T, E>&& r
15321532
template<class E, class F, class R = ...> R operator|( result<void, E> const& r, F&& f );
15331533
template<class E, class F, class R = ...> R operator|( result<void, E>&& r, F&& f );
15341534

1535+
// operator&
1536+
1537+
template<class T, class E, class F, class U = ...>
1538+
result<U, E> operator&( result<T, E> const& r, F&& f );
1539+
template<class T, class E, class F, class U = ...>
1540+
result<U, E> operator&( result<T, E>&& r, F&& f );
1541+
1542+
template<class T, class E, class F, class R = ...> R operator&( result<T, E> const& r, F&& f );
1543+
template<class T, class E, class F, class R = ...> R operator&( result<T, E>&& r, F&& f );
1544+
15351545
} // namespace system
15361546
} // namespace boost
15371547
```
@@ -2607,6 +2617,90 @@ int get_port()
26072617
}
26082618
```
26092619

2620+
#### operator&
2621+
2622+
```
2623+
template<class T, class E, class F, class U = ...>
2624+
result<U, E> operator&( result<T, E> const& r, F&& f );
2625+
2626+
template<class T, class E, class F, class U = ...>
2627+
result<U, E> operator&( result<T, E>&& r, F&& f );
2628+
```
2629+
[none]
2630+
* {blank}
2631+
+
2632+
Returns the error in `r`, or if `r` contains a value, transforms the value by calling `f` on it.
2633+
+
2634+
Let `U` be the type of `f(*r)`.
2635+
+
2636+
Effects: ::
2637+
- If `r.has_value()` is `true`, returns `f(*r)`.
2638+
- Otherwise, returns `r.error()`.
2639+
Remarks: ::
2640+
Only enabled when `U` is not an instance of `result`.
2641+
Example: ::
2642+
+
2643+
```
2644+
struct currency_type
2645+
{
2646+
char code_[ 4 ] = {};
2647+
};
2648+
2649+
result<double> get_exchange_rate( currency_type from, currency_type to );
2650+
2651+
result<double> convert( double amount, currency_type from, currency_type to )
2652+
{
2653+
return get_exchange_rate( from, to ) & [&](double rate){ return rate * amount; };
2654+
}
2655+
```
2656+
2657+
```
2658+
template<class T, class E, class F, class R = ...> R operator&( result<T, E> const& r, F&& f );
2659+
template<class T, class E, class F, class R = ...> R operator&( result<T, E>&& r, F&& f );
2660+
```
2661+
[none]
2662+
* {blank}
2663+
+
2664+
Returns the error in `r`, or if `r` contains a value, another `result` obtained
2665+
by invoking the function `f` on the value in `r`.
2666+
+
2667+
Let `R` be the type of `f(*r)`.
2668+
+
2669+
Effects: ::
2670+
- If `r.has_value()` is `true`, returns `f(*r)`.
2671+
- Otherwise, returns `r.error()`.
2672+
Remarks: ::
2673+
Only enabled when `R` is an instance of `result` and `E` is convertible to `R::error_type`.
2674+
Example: ::
2675+
+
2676+
```
2677+
struct JsonValue
2678+
{
2679+
result<JsonValue const&> at( std::size_t i ) const noexcept;
2680+
result<JsonValue const&> at( std::string_view key ) const noexcept;
2681+
template<class T> result<T> to_number() const noexcept;
2682+
};
2683+
2684+
namespace helpers
2685+
{
2686+
inline auto at( std::size_t i ) {
2687+
return [=](JsonValue const& jv){ return jv.at( i ); }; }
2688+
2689+
inline auto at( std::string_view key ) {
2690+
return [=](JsonValue const& jv){ return jv.at( key ); }; }
2691+
2692+
template<class T> inline auto to_number() {
2693+
return [](JsonValue const& jv){ return jv.to_number<T>(); }; }
2694+
2695+
} // namespace helpers
2696+
2697+
int get_port( JsonValue const& config, int def )
2698+
{
2699+
using namespace helpers;
2700+
return config.at( "servers" ) & at( 0 ) & at( "port" ) & to_number<int>() | def;
2701+
}
2702+
```
2703+
26102704
## <boost/system.hpp>
26112705

26122706
This convenience header includes all the headers previously described.

0 commit comments

Comments
 (0)