Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
negator.cpp
Go to the documentation of this file.
1
31#include <functional> // for unary_function
32#include <ios> // for boolalpha
33#include <iostream> // for cout, endl
34
35#include <examples.h>
36
37
38// Create a new predicate from unary_function.
39template <class Arg>
40struct is_odd : public std::unary_function<Arg, bool>
41{
42 bool operator() (const Arg &arg1) const {
43 return arg1 % 2 != 0;
44 }
45};
46
47
48int main ()
49{
50 std::less<int> less_func;
51
52 // Use not2 on less.
53 std::cout << std::boolalpha
54 << less_func (1, 4) << '\n'
55 << less_func (4, 1) << '\n'
56 << std::not2 (std::less<int>())(1, 4) << '\n'
57 << std::not2 (std::less<int>())(4, 1) << '\n';
58
59 // Create an instance of our predicate.
60 is_odd<int> odd;
61
62 // Use not1 on our user defined predicate.
63 std::cout << odd (1) << '\n'
64 << odd (4) << '\n'
65 << std::not1 (odd)(1) << '\n'
66 << std::not1 (odd)(4) << std::endl;
67
68 return 0;
69}
#define Arg
Definition 17.names.cpp:442
int main()
Definition negator.cpp:48
bool operator()(const Arg &arg1) const
Definition negator.cpp:42