Skip to content

Commit 41e192d

Browse files
committed
Documentation update
1 parent d3f4b00 commit 41e192d

File tree

1 file changed

+90
-55
lines changed

1 file changed

+90
-55
lines changed

doc/leaf.adoc

Lines changed: 90 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,12 @@ TIP: The automatically generated diagnostic messages are developer-friendly, but
17331733
[[tutorial-serialization]]
17341734
=== Serialization
17351735

1736-
LEAF provides a serialization API that enables exporting error information into different formats, such as JSON. This is useful for structured logging, remote debugging, or integrating with monitoring systems. To serialize error information, use the `write_to` member function available on <<error_info>>, <<diagnostic_info>>, and <<diagnostic_details>> classes.
1736+
LEAF provides a serialization API that enables exporting error information into different formats, such as JSON. This is useful for structured logging, remote debugging, or integrating with monitoring systems. To serialize error information, use the `write_to` member function available on the following types:
1737+
1738+
* <<error_info>>
1739+
* <<diagnostic_info>>
1740+
* <<diagnostic_details>>
1741+
* <<result>>
17371742

17381743
==== Custom Writers
17391744

@@ -2521,6 +2526,9 @@ namespace boost { namespace leaf {
25212526
25222527
void unload();
25232528
2529+
template <class Writer>
2530+
void write_to( Writer & w ) const;
2531+
25242532
template <class CharT, class Traits>
25252533
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> &, result const & );
25262534
};
@@ -2567,6 +2575,9 @@ namespace boost { namespace leaf {
25672575
25682576
void unload();
25692577
2578+
template <class Writer>
2579+
void write_to( Writer & w ) const;
2580+
25702581
template <class CharT, class Traits>
25712582
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> &, result const &);
25722583
};
@@ -4716,6 +4727,9 @@ namespace boost { namespace leaf {
47164727
47174728
void unload();
47184729
4730+
template <class Writer>
4731+
void write_to( Writer & w ) const;
4732+
47194733
template <class CharT, class Traits>
47204734
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> &, result const & );
47214735
};
@@ -4762,6 +4776,9 @@ namespace boost { namespace leaf {
47624776
47634777
void unload();
47644778
4779+
template <class Writer>
4780+
void write_to( Writer & w ) const;
4781+
47654782
template <class CharT, class Traits>
47664783
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> &, result const &);
47674784
};
@@ -4776,7 +4793,7 @@ namespace boost { namespace leaf {
47764793
} }
47774794
----
47784795
[.text-right]
4779-
<<result::result>> | <<result::operator_eq>> | <<result::has_value>> | <<result::has_error>> | <<result::operator_bool>> | <<result::value>> | <<result::operator_ptr>> | <<result::operator_deref>> | <<result::error>> | <<result::load>>
4796+
<<result::result>> | <<result::operator_eq>> | <<result::has_value>> | <<result::has_error>> | <<result::operator_bool>> | <<result::value>> | <<result::operator_ptr>> | <<result::operator_deref>> | <<result::error>> | <<result::load>> | <<result::write_to>>
47804797

47814798
The `result<T>` type can be returned by functions which produce a value of type `T` but may fail doing so.
47824799

@@ -4899,6 +4916,42 @@ WARNING: The returned proxy object refers to `*this`; avoid holding on to it.
48994916

49004917
'''
49014918

4919+
[[result::has_error]]
4920+
==== `has_error`
4921+
4922+
.#include <boost/leaf/result.hpp>
4923+
[source,c++]
4924+
----
4925+
namespace boost { namespace leaf {
4926+
4927+
template <class T>
4928+
bool result<T>::has_error() const noexcept;
4929+
4930+
} }
4931+
----
4932+
4933+
Returns: :: If `*this` is in <<result,value state>>, returns `false`, otherwise returns `true`.
4934+
4935+
'''
4936+
4937+
[[result::has_value]]
4938+
==== `has_value`
4939+
4940+
.#include <boost/leaf/result.hpp>
4941+
[source,c++]
4942+
----
4943+
namespace boost { namespace leaf {
4944+
4945+
template <class T>
4946+
bool result<T>::has_value() const noexcept;
4947+
4948+
} }
4949+
----
4950+
4951+
Returns: :: If `*this` is in <<result,value state>>, returns `true`, otherwise returns `false`.
4952+
4953+
'''
4954+
49024955
[[result::load]]
49034956
==== `load`
49044957

@@ -4922,79 +4975,87 @@ Returns: :: `*this`.
49224975

49234976
'''
49244977

4925-
[[result::operator_eq]]
4926-
==== `operator=`
4978+
[[result::operator_bool]]
4979+
==== `operator bool`
49274980

49284981
.#include <boost/leaf/result.hpp>
49294982
[source,c++]
49304983
----
49314984
namespace boost { namespace leaf {
49324985
49334986
template <class T>
4934-
result<T> & result<T>::operator=( result && ) noexcept;
4935-
4936-
template <class T>
4937-
template <class U>
4938-
result<T> & result<T>::operator=( result<U> && ) noexcept;
4987+
result<T>::operator bool() const noexcept;
49394988
49404989
} }
49414990
----
49424991

4943-
Effects: :: Destroys `*this`, then re-initializes it as if using the appropriate `result<T>` constructor. Basic exception-safety guarantee.
4992+
Returns: :: If `*this` is in <<result,value state>>, returns `true`, otherwise returns `false`.
49444993

49454994
'''
49464995

4947-
[[result::has_value]]
4948-
==== `has_value`
4996+
[[result::operator_deref]]
4997+
==== `operator*`
49494998

49504999
.#include <boost/leaf/result.hpp>
49515000
[source,c++]
49525001
----
49535002
namespace boost { namespace leaf {
49545003
49555004
template <class T>
4956-
bool result<T>::has_value() const noexcept;
5005+
T const & result<T>::operator*() const noexcept;
5006+
5007+
template <class T>
5008+
T & result<T>::operator*() noexcept;
49575009
49585010
} }
49595011
----
49605012

4961-
Returns: :: If `*this` is in <<result,value state>>, returns `true`, otherwise returns `false`.
5013+
Requires: :: `*this` must be in <<result,value state>>.
5014+
5015+
Returns :: a reference to the stored value.
49625016

49635017
'''
49645018

4965-
[[result::has_error]]
4966-
==== `has_error`
5019+
[[result::operator_eq]]
5020+
==== `operator=`
49675021

49685022
.#include <boost/leaf/result.hpp>
49695023
[source,c++]
49705024
----
49715025
namespace boost { namespace leaf {
49725026
49735027
template <class T>
4974-
bool result<T>::has_error() const noexcept;
5028+
result<T> & result<T>::operator=( result && ) noexcept;
5029+
5030+
template <class T>
5031+
template <class U>
5032+
result<T> & result<T>::operator=( result<U> && ) noexcept;
49755033
49765034
} }
49775035
----
49785036

4979-
Returns: :: If `*this` is in <<result,value state>>, returns `false`, otherwise returns `true`.
5037+
Effects: :: Destroys `*this`, then re-initializes it as if using the appropriate `result<T>` constructor. Basic exception-safety guarantee.
49805038

49815039
'''
49825040

4983-
[[result::operator_bool]]
4984-
==== `operator bool`
5041+
[[result::operator_ptr]]
5042+
==== `operatorpass:[->]`
49855043

49865044
.#include <boost/leaf/result.hpp>
49875045
[source,c++]
49885046
----
49895047
namespace boost { namespace leaf {
49905048
49915049
template <class T>
4992-
result<T>::operator bool() const noexcept;
5050+
T const * result<T>::operator->() const noexcept;
5051+
5052+
template <class T>
5053+
T * result<T>::operator->() noexcept;
49935054
49945055
} }
49955056
----
49965057

4997-
Returns: :: If `*this` is in <<result,value state>>, returns `true`, otherwise returns `false`.
5058+
Returns :: If `*this` is in <<result,value state>>, returns a pointer to the stored value; otherwise returns `nullptr`.
49985059

49995060
'''
50005061

@@ -5036,52 +5097,26 @@ A member type of `result<T>`, defined as a synonym for `T`.
50365097

50375098
'''
50385099

5039-
[[result::bad_result]]
5040-
Effects: :: If `*this` is in <<result,value state>>, returns a reference to the stored value, otherwise throws `bad_result`.
5041-
5042-
'''
5043-
5044-
[[result::operator_ptr]]
5045-
==== `operatorpass:[->]`
5100+
[[result::write_to]]
5101+
==== `write_to`
50465102

50475103
.#include <boost/leaf/result.hpp>
50485104
[source,c++]
50495105
----
50505106
namespace boost { namespace leaf {
50515107
50525108
template <class T>
5053-
T const * result<T>::operator->() const noexcept;
5054-
5055-
template <class T>
5056-
T * result<T>::operator->() noexcept;
5109+
template <class Writer>
5110+
void result<T>::write_to( Writer & w ) const;
50575111
50585112
} }
50595113
----
50605114

5061-
Returns :: If `*this` is in <<result,value state>>, returns a pointer to the stored value; otherwise returns 0.
5062-
5063-
'''
5064-
5065-
[[result::operator_deref]]
5066-
==== `operator*`
5067-
5068-
.#include <boost/leaf/result.hpp>
5069-
[source,c++]
5070-
----
5071-
namespace boost { namespace leaf {
5072-
5073-
template <class T>
5074-
T const & result<T>::operator*() const noexcept;
5075-
5076-
template <class T>
5077-
T & result<T>::operator*() noexcept;
5078-
5079-
} }
5080-
----
5115+
The `write_to` member function is used with the serialization system; see <<tutorial-serialization>>.
50815116

5082-
Requires: :: `*this` must be in <<result,value state>>.
5117+
If the result is in <<result,value state>>, outputs the value. If it is in <<result,error state>>, outputs the <<error_id>>. If the result holds <<try_capture_all,captured error objects>>, outputs them as well.
50835118

5084-
Returns :: a reference to the stored value.
5119+
NOTE: Result objects carry error objects only when in <<try_capture_all,capture state>>. Otherwise, to output error objects, use `write_to` on <<diagnostic_details>> in an error handling scope.
50855120

50865121
'''
50875122

0 commit comments

Comments
 (0)