Код: Выделить всё
#include
#include
#include
#include
using std::vector;
using std::random_device;
using std::mt19937;
using std::uniform_int_distribution;
using std::next;
using std::cout;
using std::endl;
int func()
{
struct data
{
int i;
char c;
};
//vector of alphabets
vectorvA;
using VID = vector::iterator;
using VVID = vector;
VVID vVow;
VVID vCons;
auto fillVA = [&](int numEl)->void
{
char alphabets[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
auto const distRng = sizeof(alphabets)/sizeof(alphabets[0]);
random_device rd;
mt19937 gen(rd());
uniform_int_distribution distrib(0, distRng - 1);
for(auto count = 0; count < numEl; ++count)
{
data d;
d.i = count;
auto idx = distrib(gen);
d.c = alphabets[idx];
vA.push_back(d);
}
};
auto fndVow = [](char c)->bool
{
char vowels[] = {'a','e','i','o','u'};
constexpr size_t size = sizeof(vowels)/sizeof(vowels[0]);
for(auto count = 0; count < (int)size; ++count)
{
if(c == vowels[count])
{
return true;
}
}
return false;
};
auto prntvVow = [&]()->void
{
for(auto iter : vVow)
{
cout c c;
if( c > (*iterBef)->c && c < (*iterAft)->c)
{
auto d = **revIter;
vVow.insert(iterAft,d);
}
++revIter;
}
iterBef = iterAft;
iterAft = next(iterBef,1);
}
prntvVow();
return 0;
}
int main() {
auto exit = (int (*)()) &func;
std::cout
auto d = **revIter;
< /code>
Компилятор генерирует следующую ошибку: < /p>
error: no matching function for call to ‘std::vector::insert(__gnu_cxx::__normal_iterator&, func()::data&)’
| vVow.insert(iterAft,d);
| ~~~~~~~~~~~^~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
< /code>
Я был убежден использовать приведенную выше конструкцию, учитывая следующий код чуть выше компилирования без ошибок: < /p>
auto c = (*revIter)->c;
Подробнее здесь: https://stackoverflow.com/questions/797 ... o-iterator