Translated using Weblate (Chinese (Simplified))
[cygwin-setup.git] / Generic.h
blob44c6697986ca00c7b0bbb2beaca9df5b3ccfa332
1 /*
2 * Copyright (c) 2003 Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <robertc@hotmail.com>
16 #ifndef SETUP_GENERIC_H
17 #define SETUP_GENERIC_H
19 template <class _Visitor, class _Predicate>
20 struct _visit_if {
21 _visit_if(_Visitor v, _Predicate p) : visitor(v), predicate (p) {}
22 void operator() (typename _Visitor::argument_type& arg) {
23 if (predicate(arg))
24 visitor(arg);
26 _Visitor visitor;
27 _Predicate predicate;
30 template <class _Visitor, class _Predicate>
31 _visit_if<_Visitor, _Predicate>
32 visit_if(_Visitor visitor, _Predicate predicate)
34 return _visit_if<_Visitor, _Predicate>(visitor, predicate);
37 #endif /* SETUP_GENERIC_H */