fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <string>
  4. #include <vector>
  5.  
  6. struct PasswordVerifier {
  7. bool operator()(const std::string &password) {
  8. std::cout << "password: " << password << std::endl;
  9. return false;
  10. }
  11. };
  12.  
  13. struct IdCardVerifier {
  14. bool operator()(const std::vector<int> &id_value) {
  15. std::cout << "id_value: ";
  16. std::copy(id_value.begin(), id_value.end(), std::ostream_iterator<int>(std::cout, ","));
  17. return false;
  18. }
  19. };
  20.  
  21. template<class Verifier, class... Args>
  22. bool verify(Args&&... args) {
  23. return Verifier()(std::forward<Args>(args)...);
  24. }
  25.  
  26. int main() {
  27. verify<PasswordVerifier>("this_is_my_password");
  28. verify<IdCardVerifier>(std::vector<int>({0, 1, 2, 3}));
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
password: this_is_my_password
id_value: 0,1,2,3,