@@ -204,51 +204,55 @@ void Deduce(doc::Properties& p) {
204
204
}
205
205
#+END_SRC
206
206
207
- * ~In Out~
207
+ * ~Out~ Object Reference
208
208
209
209
#+BEGIN_EXPORT latex
210
- \invisible{hi}\vspace{-2em} % remove unnecessary vspace due to minted
211
- \hfill\begin{tabular}{@{}p{0.4\linewidth}@{}} % align horizontally in page
212
- \vspace{-3em} % align vertically with section title
210
+ \invisible{hi}\vspace{-1.5em}
211
+ \hfill\begin{tabular}{@{}p{0.4\linewidth}@{}}
212
+ \vspace{-3em}
213
213
#+END_EXPORT
214
214
215
215
#+BEGIN_SRC c++
216
- void f(T&);
216
+ T& f();
217
+ const T& f();
217
218
#+END_SRC
218
219
219
220
#+LATEX: \end{tabular}
220
221
221
- Objects for /reading/ and /writing/: *lvalue reference*
222
+ Return *lvalue reference* to /object outliving function and caller/
222
223
223
224
#+BEGIN_SRC c++
224
225
// example
225
- void AdjustMargins(std::vector<Margin>& margins) {
226
- }
226
+ struct Application {
227
+ Document& GetDocument { return m_pdf; } // covariant return type
228
+ PDFDocument m_pdf;
229
+ }; // app outlives GetDocument() and temp() calls
230
+ void PrintDoc(Application& app) { app.GetDocument().Print(); }
231
+ int main() { Application app{str_pdf_path}; PrintDoc(app); }
227
232
#+END_SRC
228
233
229
- * Perfect Forwarding
234
+ * ~In Out~
230
235
231
236
#+BEGIN_EXPORT latex
232
- \invisible{hi}\vspace{-1.5em}
233
- \hfill\begin{tabular}{@{}p{0.4\linewidth}@{}}
234
- \vspace{-3em}
237
+ \invisible{hi}\vspace{-2em} % remove unnecessary vspace due to minted
238
+ \hfill\begin{tabular}{@{}p{0.4\linewidth}@{}} % align horizontally in page
239
+ \vspace{-3em} % align vertically with section title
235
240
#+END_EXPORT
236
241
237
242
#+BEGIN_SRC c++
238
- template <typename T>
239
- void f(T&&);
243
+ void f(T&);
240
244
#+END_SRC
241
245
242
246
#+LATEX: \end{tabular}
243
247
244
- Pass parameter retaining lvalue/rvalue-/ness/ : *forwarding reference*
248
+ Objects for /reading/ and /writing/ : *lvalue reference*
245
249
246
250
#+BEGIN_SRC c++
247
- template <typename T>
248
- void SetTiel(T&& title) {
249
- internal::SetTitle(std::forward<T>(title));
251
+ // example
252
+ void AdjustMargins(std::vector<Margin>& margins) {
250
253
}
251
254
#+END_SRC
252
255
256
+
253
257
#+LATEX: \vspace{0.75em}
254
258
*Reference*: [[https://github.com/CppCon/CppCon2014/blob/master/Presentations/Back%2520to%2520the%2520Basics!%2520Essentials%2520of%2520Modern%2520C%252B%252B%2520Style/Back%2520to%2520the%2520Basics!%2520Essentials%2520of%2520Modern%2520C%252B%252B%2520Style%2520-%2520Herb%2520Sutter%2520-%2520CppCon%25202014.pdf][Essentials of Modern C++ Style, /Herb Sutter/]]
0 commit comments