Dukales

filter

Aug 16th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. #include <cstdlib>
  4.  
  5. struct test
  6.     //: boost::static_visitor<>
  7. {
  8.  
  9.     using result_type = void;
  10.  
  11.     template< typename... P >
  12.     result_type apply_filter(P &&... _p) const
  13.     {
  14.         return operator () (filter(_p)...);
  15.     }
  16.  
  17.     template< typename... T >
  18.     result_type operator () (std::string const & _s, T &&... _tail) const
  19.     {
  20.         std::cout << _s << std::endl;
  21.         return operator () (std::forward< T >(_tail)...);
  22.     }
  23.    
  24.     template< typename... T >
  25.     result_type operator () (double const & _x, T &&... _tail) const
  26.     {
  27.         std::cout << _x << std::endl;
  28.         return operator () (std::forward< T >(_tail)...);
  29.     }
  30.  
  31. private :
  32.    
  33.     result_type operator () () const { return; }
  34.  
  35.     std::string filter(std::string const & _s) const
  36.     {
  37.         return "\"" + _s + "\"";
  38.     }
  39.    
  40.     double filter(double const & _x) const
  41.     {
  42.         return _x + 1.0;
  43.     }
  44.  
  45. };
  46.  
  47. int main()
  48. {
  49.     test const test_;
  50.     test_.apply_filter(1.0, "x", 0.0, "y");
  51.     return EXIT_SUCCESS;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment