станд.:: вектор функций

При использовании подробной формы синтаксиса код будет подробным. Вот альтернатива:

List<Tag> result = 
  db.Tags
  .GroupBy(t => t.Tag)
  .Select(g => new {Tag = g.Key, Frequency = g.Count()})
  .OrderByDescending(t => t.Frequency)
  .Take(25)
  .ToList()
  .Select(t => new Tag(){Tag = t.Tag, Frequency = t.Frequency})
  .ToList();
12
задан 11 July 2009 в 00:33
поделиться

3 ответа

Try using a typedef:

typedef void (*SDLEventFunction)(SDL_Event *);
std::vector<SDLEventFunction> functions;
16
ответ дан 2 December 2019 в 06:09
поделиться

If you like boost then then you could do it like this:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <vector>

void f1(SDL_Event *event)
{
    // ...
}

void f2(SDL_Event *event)
{
    // ...
}


int main()
{
    std::vector<boost::function<void(SDL_Event*)> > functions;
    functions.push_back(boost::bind(&f1, _1));
    functions.push_back(boost::bind(&f2, _1));

    // invoke like this:
    SDL_Event * event1 = 0; // you should probably use
                            // something better than 0 though..
    functions[0](event1);
    return 0;
}
1
ответ дан 2 December 2019 в 06:09
поделиться

Try this:

std::vector<void ( *)( SDL_Event *)> functions;
8
ответ дан 2 December 2019 в 06:09
поделиться
Другие вопросы по тегам:

Похожие вопросы: