SHOW:
|
|
- or go back to the newest paste.
1 | - | template<class Compare> |
1 | + | char randChar() |
2 | - | class ReverseCompare |
2 | + | |
3 | return 'a' + rand() % 26; | |
4 | - | ReverseCompare(Compare comp) |
4 | + | } |
5 | - | :comp(comp) |
5 | + | |
6 | - | {} |
6 | + | string randString(int maxLen = 20) |
7 | { | |
8 | - | template<class Value> |
8 | + | size_t len = rand() % maxLen; |
9 | - | bool operator(const Value& a, const Value& b) const |
9 | + | |
10 | - | { |
10 | + | string result(len, ' '); |
11 | - | return !comp(a, b); |
11 | + | std::generate_n(result.begin(), len, randChar); |
12 | - | } |
12 | + | |
13 | return result; | |
14 | - | Compare comp; |
14 | + | } |
15 | - | }; |
15 | + | // это компилится |
16 | ||
17 | //ниже не компилится ( с ошибкой: | |
18 | /* /usr/include/c++/4.7/bits/stl_algo.h: In instantiation of ‘_OIter std::generate_n(_OIter, _Size, _Generator) [with _OIter = __gnu_cxx::__normal_iterator<std::basic_string<char>*, std::vector<std::basic_string<char> > >; _Size = long unsigned int; _Generator = std::basic_string<char> (*)(int)]’: | |
19 | main.cpp:63:50: required from here | |
20 | /usr/include/c++/4.7/bits/stl_algo.h:5113:2: error: too few arguments to function */ | |
21 | ||
22 | vector<string> genRandomStrings(int maxSize) | |
23 | { | |
24 | size_t n = rand() % maxSize; | |
25 | ||
26 | vector<string> result(n, ""); | |
27 | std::generate_n(result.begin(), n, randString); | |
28 | //result[0] = randString(); | |
29 | ||
30 | return result; | |
31 | } |