-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFp2.hpp
122 lines (89 loc) · 2.3 KB
/
Fp2.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// Fp2.hpp
// Fp
//
// Created by Roberto Capuano on 27/11/2018.
// Copyright © 2018 Roberto Capuano. All rights reserved.
//
#ifndef Fp2_hpp
#define Fp2_hpp
#include <functional>
#include <algorithm>
using namespace std;
template< typename T >
class SeqR
{
public:
using OP = void( typename T::value_type &);
using PRED = bool(const typename T::value_type &);
using MAP = typename T::value_type(typename T::value_type &);
T &seq;
SeqR( T &seq )
: seq( seq )
{}
void forEach( function<OP> op ) {
for_each( begin(seq), end(seq), op );
};
SeqR<T> &filter( function<SeqR::PRED> pred )
{
remove_if( begin(seq), end(seq), [&] (auto x) { return !pred(x); } );
return *this;
}
SeqR<T> &map( function<SeqR::MAP> mapper )
{
transform( begin(seq), end(seq), begin(seq), mapper );
return *this;
}
SeqR<T> &sort( )
{
std::sort( begin(seq), end(seq) );
return *this;
}
SeqR<T> &ort( function<SeqR::MAP> comp )
{
std::sort( begin(seq), end(seq), comp );
return *this;
}
// size_t find( const typename T::value_type &v ) {
// auto it = std::find( cbegin(seq), cend(seq), v );
//
// return it - cbegin(seq);
// }
bool exist( const typename T::value_type &&v ) {
auto it = std::find( cbegin(seq), cend(seq), v );
return it!=cend(seq);
}
bool exist( function<SeqR::PRED> pred ) {
auto it = std::find( cbegin(seq), cend(seq), pred );
return it!=cend(seq);
}
const typename T::value_type find( function<SeqR::PRED> pred ) {
auto it = find_if( cbegin(seq), cend(seq), pred );
if (it==cend(seq))
return typename T::value_type();
return *it;
}
const T& get() { return seq; }
};
template< typename T >
class SeqV : public SeqR<T>
{
public:
T seqv;
SeqV( T _seqv )
: SeqR<T>(seqv),
seqv( _seqv )
{}
T get() { return seqv; }
};
template <typename T>
SeqV<T> NEWSEQ( T seqv )
{
return SeqV<T>( seqv );
}
template <typename T>
SeqR<T> SEQ( T &seqv )
{
return SeqR<T>( seqv );
}
#endif /* Fp2_hpp */