Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use code-like formatting on code example #445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions _posts/2023-01-19-totw-218.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,24 @@ a friend function template in their type named `SketchyDraw` with the
appropriate signature. the template overload above will use ADL to find the
`SketchyDraw` function. For example,

</pre>
<pre class="prettyprint lang-cpp code">
class Triangle {
public:
explicit Triangle(Point a, Point b, Point c) : a_(a), b_(b), c_(c) {}

template &lt;typename SC&gt; friend void SketchyDraw(SC& canvas, const Triangle&
triangle) { // Note: This is a template, even though the only type we ever
expect to be // passed in for `SC` is `sketchy::Canvas`. Using `sketchy::Canvas`
directly // works, but pulls in an extra dependency that may not be used by all
users // of `Triangle`. sketchy::Draw(canvas, sketchy::Line(triangle.a_,
triangle.b_)); sketchy::Draw(canvas, sketchy::Line(triangle.b_, triangle.c_));
sketchy::Draw(canvas, sketchy::Line(triangle.c_, triangle.a_)); }
template &lt;typename SC&gt; friend void SketchyDraw(SC& canvas, const Triangle&
triangle) { // Note: This is a template, even though the only type we ever expect to be
// passed in for `SC` is `sketchy::Canvas`. Using `sketchy::Canvas` directly
// works, but pulls in an extra dependency that may not be used by all users
// of `Triangle`.
sketchy::Draw(canvas, sketchy::Line(triangle.a_, triangle.b_));
sketchy::Draw(canvas, sketchy::Line(triangle.b_, triangle.c_));
sketchy::Draw(canvas, sketchy::Line(triangle.c_, triangle.a_));
}

private: Point a_, b_, c_; };
private:
Point a_, b_, c_;
};

// Usage:
void DrawTriangles(sketchy::Canvas& canvas, absl::Span&lt;const Triangle&gt; triangles) {
Expand Down