Punchcard

Lambda in constructor

Jun 17th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | Source Code | 0 0
  1. #include <numeric>
  2. #include <iostream>
  3. #include <string>
  4. #include <set>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. class SearchServer
  9. {
  10. public:
  11.    
  12.     explicit SearchServer(const string& str) {
  13.                            
  14.         cout << "String "s << str << " has been converted to a set of stop words"s << endl;                            
  15.  
  16.     }
  17.     template <typename StringCollection>
  18.     explicit SearchServer(const StringCollection& splitted_string) : SearchServer([splitted_string]() -> string {return accumulate(splitted_string.begin(), splitted_string.end(), string{});})
  19.     {
  20.         cout << "Container has been converted to a string and sent to constructor"s << endl;
  21.     }
  22. };
  23.  
  24. int main() {
  25.    
  26.     SearchServer ss1("one two three"s);
  27.     vector<string> in_v = {"four"s, "five"s, "six"s};
  28.     SearchServer ss2(in_v);
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment