Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
replace.h
Go to the documentation of this file.
1
29#ifndef REPLACE_H_INCLUDED
30#define REPLACE_H_INCLUDED
31
32#include <functional>
33
34struct is_prime: public std::unary_function<short, bool>
35{
36 bool operator() (const short&) const;
37};
38
39
40bool is_prime::operator() (const short &a) const
41{
42 // all primes smaller than 256
43 static const unsigned short primes[] = {
44 2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 23, 25, 29, 31, 35,
45 37, 41, 43, 47, 49, 53, 59, 61, 67, 71, 73, 79, 83, 89,
46 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139,
47 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 191,
48 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251
49 };
50
51 const unsigned short *end = primes + sizeof primes / sizeof *primes;
52
53 // search primes for a divisor
54 for (const unsigned short *p = primes; p != end; ++p)
55 if (0 == a % *p)
56 return false;
57
58 return 0 != a;
59}
60
61#endif // REPLACE_H_INCLUDED
#define a
Definition 17.names.cpp:109
#define p
Definition 17.names.cpp:132
const int end
bool operator()(const short &) const
Definition replace.h:40