Лямбда в качестве параметра по умолчанию для шаблона функции-члена

#include <functional>

struct Check {};
struct Entry {};
struct Table {};

class SeatEntries
{
public:
// does not compile!
template<class T>
void Populate(T from,
std::function<bool (Entry *)> predicate = [] (Entry *) { return true; },
std::function<void (Entry *)> action = [] (Entry *) {})
{
Reset();
PopulateImpl(from, predicate, action);
}

// compiles!
void PopulateFromCheck(Check *from,
std::function<bool (Entry *)> predicate = [] (Entry *) { return true; },
std::function<void (Entry *)> action = [] (Entry *) {})
{
Reset();
//PopulateImpl(from, predicate, action);
}

void Reset();

private:
template<class T>
void PopulateImpl(T from,
std::function<bool (Entry *)> predicate,
std::function<void (Entry *)> action);
};

template<>
void SeatEntries::PopulateImpl<Table *>(Table *from, std::function<bool (Entry *)> predicate, std::function<void (Entry *)> action);

template<>
void SeatEntries::PopulateImpl<Check *>(Check *from, std::function<bool (Entry *)> predicate, std::function<void (Entry *)> action);

Почему первый шаблон функции-члена не компилируется? Это ошибка как в VS2012, так и в gcc 4.8.1? Не знаю ли я о некоторых фактах, касающихся шаблонов функций-членов и лямбда-выражений в качестве параметров по умолчанию?

Выход VS2012

error C2958: the left parenthesis '(' found at 'seathelpers.h(33)' was not matched correctly
error C2988: unrecognizable template declaration/definition
error C2059: syntax error : '{'
error C2334: unexpected token(s) preceding '{'; skipping apparent function body

Упомянутые левые скобки являются открывающими скобками для шаблона функции Populate ().

GCC 4.8.1 (MinGW)

Test.h:13:66: internal compiler error: in push_class_level_binding_1, at cp/name-lookup.c:3019
std::function<bool (Entry *)> predicate = [] (Entry *) { return true; },
^

3

Решение

Мне удалось без ошибок скомпилировать приведенный выше код с помощью gcc 4.8.3

$ g++ --version
g++ (GCC) 4.8.3 20140624 (Red Hat 4.8.3-1)
1

Другие решения


По вопросам рекламы ammmcru@yandex.ru
Adblock
detector