C++11 book notation

C++11 book notation



Could someone explain to me this notation from Stroustrup's book?


template<typename Cont, typename Pred>
std::vector<Value_type<Cont>*>
find_all(Cont& c, Pred p)

std::vector<Value_type<Cont>*> res;
for(auto& x :c)
if(p(x)) res.push_back(&x);
return res;



How should I understand value_type here? This is not a keyword from C++ and not Cont::value_type, then what?


value_type


Cont::value_type



The example is form C11 Bjarne Starstroup book.
Chapter 32.2 Algorithms snippet 4th.





Value_type must be defined somewhere before this code in the book
– NathanOliver
Aug 28 '18 at 19:40


Value_type





It is probably something like template <typename T> using Value_type<T> = typename T::value_type;
– NathanOliver
Aug 28 '18 at 19:44



template <typename T> using Value_type<T> = typename T::value_type;





Please also mention the title of the book, version, and page number. Stroustrup has three published books about C++, one of which is on its fourth edition.
– jaggedSpire
Aug 29 '18 at 13:52





@jaggedSpire I have this book and the snippet on page 672 doesn't match the one in question. And most probably it's not this book, as there is no mention of Value_type in the index (of course, there is value_type).
– BartoszKP
Aug 29 '18 at 20:48



Value_type


value_type





And in the book is clearly Value_type not value_type!
– Tomasz Kaleta
Sep 4 '18 at 7:25




1 Answer
1



See 28.2.4 of the book.


template<typename T>
using Value_type = typename std::iterator_trait<T>::value_type;





And now we are talking. Thanks. First non-evasive answer :)
– Tomasz Kaleta
Sep 4 '18 at 9:19





Shame 4 the rest.
– Tomasz Kaleta
Sep 4 '18 at 9:20





By the way std::iterator_traits :P
– Tomasz Kaleta
Sep 4 '18 at 9:30



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế