mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 11:12:25 +01:00
cleans up description
capitalization, adds ref to pair type.
This commit is contained in:
parent
bffc8eae34
commit
dd6de240dc
@ -1,16 +1,16 @@
|
|||||||
# Making Types Printable
|
# Making Types Printable
|
||||||
|
|
||||||
Catch is capable of using user defined print functions and overloads.
|
Catch can print many standard types out of the box, but it is also capable of using user defined print functions and overloads.
|
||||||
|
|
||||||
## Using ostreams
|
## Using ostream and operator<<
|
||||||
|
|
||||||
By default, catch will attempt to display types using an ostream overload is available.
|
By default, catch will attempt to display a variable of type `T` using an ostream overload if available.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
std::ostream& operator<<(std::ostream&, MySpecialType const&);
|
std::ostream& operator<<(std::ostream&, T const&);
|
||||||
```
|
```
|
||||||
|
|
||||||
## using toString
|
## Overloading Catch::toString
|
||||||
If you don't want your type to work with ostreams, or Catch is unable to find the
|
If you don't want your type to work with ostreams, or Catch is unable to find the
|
||||||
overload you provide, you may alternatively overload `Catch::toString`. The overload
|
overload you provide, you may alternatively overload `Catch::toString`. The overload
|
||||||
must appear **above** the include of `catch.hpp`. For example, if I want to provide
|
must appear **above** the include of `catch.hpp`. For example, if I want to provide
|
||||||
@ -23,7 +23,7 @@ would look like this:
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
std::string toString(std::pair<int, char> const p) {
|
std::string toString(std::pair<int, char> const& p) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << '{' << p.first << ", " << p.second << '}';
|
oss << '{' << p.first << ", " << p.second << '}';
|
||||||
return oss.str();
|
return oss.str();
|
||||||
@ -37,4 +37,4 @@ due to possible typos when typing `Catch` or `toString`
|
|||||||
|
|
||||||
## Default output
|
## Default output
|
||||||
|
|
||||||
If neither of the two conditions has been met, catch will output `{?}` by default.
|
If neither of the two conditions has been met, and catch does not provide a string conversion for the type, catch will output `{?}` by default.
|
||||||
|
Loading…
Reference in New Issue
Block a user